PHP - Pinball Simulation
Hi
I am still learning PHP and have a project due. I haven't had any PHP classes so I am struggling with this project. It is suppose to be a text only output pinball simulation. It calculates the players skill level randomly, there are 4 bumpers and for banks, it calculates how many times each bumper and bank is hit and calculates the score outputting all info in text no formatting. My code looks like it should work but doesn't output correctly and I can't figure out way. Here is the output : Notice: Undefined variable: skillLevel in C:\xampp\htdocs\pinball.php on line 39 Notice: Undefined variable: skillLevel in C:\xampp\htdocs\pinball.php on line 39 Notice: Undefined variable: skillLevel in C:\xampp\htdocs\pinball.php on line 42 Notice: Undefined variable: skillLevel in C:\xampp\htdocs\pinball.php on line 42 Notice: Undefined variable: skillLevel in C:\xampp\htdocs\pinball.php on line 45 Notice: Undefined variable: skillLevel in C:\xampp\htdocs\pinball.php on line 45 Notice: Undefined variable: skillLevel in C:\xampp\htdocs\pinball.php on line 48 Notice: Undefined variable: skillLevel in C:\xampp\htdocs\pinball.php on line 48 Notice: Undefined variable: skillLevel in C:\xampp\htdocs\pinball.php on line 51 Notice: Undefined variable: skillLevel in C:\xampp\htdocs\pinball.php on line 51 Notice: Undefined variable: skillLevel in C:\xampp\htdocs\pinball.php on line 54 Notice: Undefined variable: skillLevel in C:\xampp\htdocs\pinball.php on line 54 Welcome To God Mode! Ball Launched! Notice: Undefined variable: skillLevel in C:\xampp\htdocs\pinball.php on line 64 Bumper 4 Hit. Bumper 2 Hit. Bank 2 Hit! Notice: Undefined variable: bank2 in C:\xampp\htdocs\pinball.php on line 441 Damn You Suck!!!! Notice: Undefined variable: bank1 in C:\xampp\htdocs\pinball.php on line 905 Notice: Undefined variable: bank1Pegs in C:\xampp\htdocs\pinball.php on line 907 Notice: Undefined variable: bank1 in C:\xampp\htdocs\pinball.php on line 905 Notice: Undefined variable: bank1 in C:\xampp\htdocs\pinball.php on line 905 Notice: Undefined variable: bank1 in C:\xampp\htdocs\pinball.php on line 905 Notice: Undefined variable: bank1 in C:\xampp\htdocs\pinball.php on line 905 Notice: Undefined variable: bank1 in C:\xampp\htdocs\pinball.php on line 905 Notice: Undefined variable: bank2 in C:\xampp\htdocs\pinball.php on line 913 Notice: Undefined variable: bank2Pegs in C:\xampp\htdocs\pinball.php on line 915 Notice: Undefined variable: bank2 in C:\xampp\htdocs\pinball.php on line 913 Notice: Undefined variable: bank2 in C:\xampp\htdocs\pinball.php on line 913 Notice: Undefined variable: bank2 in C:\xampp\htdocs\pinball.php on line 913 Notice: Undefined variable: bank2 in C:\xampp\htdocs\pinball.php on line 913 Notice: Undefined variable: bank2 in C:\xampp\htdocs\pinball.php on line 913 Notice: Undefined variable: bank3 in C:\xampp\htdocs\pinball.php on line 921 Notice: Undefined variable: bank3Pegs in C:\xampp\htdocs\pinball.php on line 923 Notice: Undefined variable: bank3 in C:\xampp\htdocs\pinball.php on line 921 Notice: Undefined variable: bank3 in C:\xampp\htdocs\pinball.php on line 921 Notice: Undefined variable: bank3 in C:\xampp\htdocs\pinball.php on line 921 Notice: Undefined variable: bank3 in C:\xampp\htdocs\pinball.php on line 921 Notice: Undefined variable: bank3 in C:\xampp\htdocs\pinball.php on line 921 Notice: Undefined variable: bank4 in C:\xampp\htdocs\pinball.php on line 929 Notice: Undefined variable: bank4Pegs in C:\xampp\htdocs\pinball.php on line 931 Notice: Undefined variable: bank4 in C:\xampp\htdocs\pinball.php on line 929 Notice: Undefined variable: bank4 in C:\xampp\htdocs\pinball.php on line 929 Notice: Undefined variable: bank4 in C:\xampp\htdocs\pinball.php on line 929 Notice: Undefined variable: bank4 in C:\xampp\htdocs\pinball.php on line 929 Notice: Undefined variable: bank4 in C:\xampp\htdocs\pinball.php on line 929 Notice: Undefined variable: score in C:\xampp\htdocs\pinball.php on line 946 Notice: Undefined variable: bumper1Hits in C:\xampp\htdocs\pinball.php on line 951 Notice: Undefined variable: bumper2Hits in C:\xampp\htdocs\pinball.php on line 952 Notice: Undefined variable: bumper3Hits in C:\xampp\htdocs\pinball.php on line 953 Notice: Undefined variable: bumper4Hits in C:\xampp\htdocs\pinball.php on line 955 GAME OVER! Your Sco Number Of Pegs Left In Bank 1: 6; Number Of Pegs Left In Bank 2: ; Number Of Pegs Left In Bank 3: 6; Number Of Pegs Left In Bank 4: 6; Number Bumper 1 Hit: Number Bumper 2 Hit: Number Bumper 3 Hit: Number Bumper 4 Hit: Refresh Page To Play Again! Here is the code: Code: [Select] <?php $score; $bank1PegsNotHit; $bank2PegsNotHit; $bank3PegsNotHit; $bank4PegsNotHit; $bumper1Hits; $bumper2Hits; $bumper3Hits; $bumper4Hits; $skillLevel = 2 - (getRandom() * 0.01); $bank1[0] = true; $bank1[1] = true; $bank1[2] = true; $bank1[3] = true; $bank1[4] = true; $bank1[5] = true; $bank2[0] = true; $bank2[1] = true; $bank2[2] = true; $bank2[3] = true; $bank2[4] = true; $bank2[5] = true; $bank3[0] = true; $bank3[1] = true; $bank3[2] = true; $bank3[3] = true; $bank3[4] = true; $bank3[5] = true; function launch() { $player; switch ($skillLevel) { case $skillLevel < 1.1: $player = " First Timer"; break; case $skillLevel < 1.2: $player = " Beginer"; break; case $skillLevel < 1.3: $player = " Regular"; break; case $skillLevel < 1.4: $player = " Advanced"; break; case $skillLevel < 1.5: $player = " Pro"; break; case $skillLevel < 1.6: $player = " Olympic "; break; default: $player = " God "; break; } echo "Welcome To<strong>$player</strong>Mode!<br />Ball Launched!<br /><br />"; switch ($i = $skillLevel * getRandom()) { case $i <= 5: hole(); break; case $i <= 20: flipper(); break; case $i <= 25: bumper4(); break; case $i <= 30: bumper3(); break; case $i <= 65: bumper1(); break; default: bumper4(); break; } } function bumper1() { global $score; $score+= 100; global $bumper1Hits; $bumper1Hits += 1; echo "<br />Bumper 1 Hit."; switch ($i = getRandom()) { case $i <= 25: bumper2(); break; case $i <= 50: bumper3(); break; case $i <= 60: bumper4(); break; case $i <= 70: bank1(); break; case $i <= 75: bank2(); break; case $i <= 80: bank3(); break; case $i <= 95: flipper(); break; default: hole(); break; } } function bumper2() { global $score; $score+= 100; global $bumper1Hits; $bumper1Hits += 1; echo "<br />Bumper 2 Hit."; switch ($i = getRandom()) { case $i <= 25: bumper1(); break; case $i <= 35: bumper3(); break; case $i <= 60: bumper4(); break; case $i <= 65: bank1(); break; case $i <= 75: bank2(); break; case $i <= 80: bank4(); break; case $i <= 95: flipper(); break; default: hole(); break; } } function bumper3() { global $score; $score+= 500; global $bumper1Hits; $bumper1Hits += 1; echo "<br />Bumper 3 Hit."; switch ($i = getRandom()) { case $i <= 25: bumper1(); break; case $i <= 35: bumper2(); break; case $i <= 60: bumper4(); break; case $i <= 65: bank1(); break; case $i <= 90: bank3(); break; case $i <= 95: flipper(); break; default: hole(); break; } } function bumper4() { global $score; $score+= 500; global $bumper1Hits; $bumper1Hits += 1; echo "<br />Bumper 4 Hit."; switch ($i = getRandom()) { case $i <= 10: bumper1(); break; case $i <= 35: bumper2(); break; case $i <= 60: bumper3(); break; case $i <= 65: bank2(); break; case $i <= 90: bank4(); break; case $i <= 95: flipper(); break; default: hole(); break; } } function bank1() { echo "<br />Bank 1 Hit!"; switch ($i = getRandom()) { case $i <= 16: if ($bank1[0]) { global $score; $score+= 10; global $bank1; $bank1[0] = false; } switch ($i = getRandom()) { case $i <= 40; bumper1(); break; case $i <= 80: bumper2(); break; case $i <= 95: flipper(); break; default: hole(); break; } break; case $i <= 32: if ($bank1[1]) { global $score; $score+= 10; global $bank1; $bank1[1] = false; } switch ($i = getRandom()) { case $i <= 40; bumper1(); break; case $i <= 80: bumper2(); break; case $i <= 95: flipper(); break; default: hole(); break; } break; case $i <= 48: if ($bank1[2]) { global $score; $score+= 10; global $bank1; $bank1[2] = false; } switch ($i = getRandom()) { case $i <= 40; bumper1(); break; case $i <= 80: bumper2(); break; case $i <= 95: flipper(); break; default: hole(); break; } break; case $i <= 64: if ($bank1[3]) { global $score; $score+= 10; global $bank1; $bank1[3] = false; } switch ($i = getRandom()) { case $i <= 40; bumper1(); break; case $i <= 80: bumper2(); break; case $i <= 95: flipper(); break; default: hole(); break; } break; case $i <= 80: if ($bank1[4]) { global $score; $score+= 10; global $bank1; $bank1[4] = false; } switch ($i = getRandom()) { case $i <= 40; bumper1(); break; case $i <= 80: bumper2(); break; case $i <= 95: flipper(); break; default: hole(); break; } break; case $i <= 96: if ($bank1[5]) { global $score; $score+= 10; global $bank1; $bank1[5] = false; } switch ($i = getRandom()) { case $i <= 40; bumper1(); break; case $i <= 80: bumper2(); break; case $i <= 95: flipper(); break; default: hole(); break; } break; case $i <= 99; flipper(); break; default: hole(); break; } } function bank2() { echo "<br />Bank 2 Hit!"; switch ($i = getRandom()) { case $i <= 16: if ($bank2[0]) { global $score; $score+= 10; global $bank2; $bank2[0] = false; } switch ($i = getRandom()) { case $i <= 40; bumper1(); break; case $i <= 80: bumper2(); break; case $i <= 95: flipper(); break; default: hole(); break; } break; case $i <= 32: if ($bank2[1]) { global $score; $score+= 10; global $bank2; $bank2[1] = false; } switch ($i = getRandom()) { case $i <= 40; bumper1(); break; case $i <= 80: bumper2(); break; case $i <= 95: flipper(); break; default: hole(); break; } break; case $i <= 48: if ($bank2[2]) { global $score; $score+= 10; global $bank2; $bank2[2] = false; } switch ($i = getRandom()) { case $i <= 40; bumper1(); break; case $i <= 80: bumper2(); break; case $i <= 95: flipper(); break; default: hole(); break; } break; case $i <= 64: if ($bank2[3]) { global $score; $score+= 10; global $bank2; $bank2[3] = false; } switch ($i = getRandom()) { case $i <= 40; bumper1(); break; case $i <= 80: bumper2(); break; case $i <= 95: flipper(); break; default: hole(); break; } break; case $i <= 80: if ($bank2[4]) { global $score; $score+= 10; global $bank2; $bank2[4] = false; } switch ($i = getRandom()) { case $i <= 40; bumper1(); break; case $i <= 80: bumper2(); break; case $i <= 95: flipper(); break; default: hole(); break; } break; case $i <= 96: if ($bank2[5]) { global $score; $score+= 10; global $bank2; $bank2[5] = false; } switch ($i = getRandom()) { case $i <= 40; bumper1(); break; case $i <= 80: bumper2(); break; case $i <= 95: flipper(); break; default: hole(); break; } break; case $i <= 99; flipper(); break; default: hole(); break; } } function bank3() { echo "<br />Bank 3 Hit!"; switch ($i = getRandom()) { case $i <= 16: if ($bank3[0]) { global $score; $score+= 10; global $bank3; $bank3[0] = false; } switch ($i = getRandom()) { case $i <= 40; bumper1(); break; case $i <= 80: bumper2(); break; case $i <= 95: flipper(); break; default: hole(); break; } break; case $i <= 32: if ($bank3[1]) { global $score; $score+= 10; global $bank3; $bank3[1] = false; } switch ($i = getRandom()) { case $i <= 40; bumper1(); break; case $i <= 80: bumper2(); break; case $i <= 95: flipper(); break; default: hole(); break; } break; case $i <= 48: if ($bank3[2]) { global $score; $score+= 10; global $bank3; $bank3[2] = false; } switch ($i = getRandom()) { case $i <= 40; bumper1(); break; case $i <= 80: bumper2(); break; case $i <= 95: flipper(); break; default: hole(); break; } break; case $i <= 64: if ($bank3[3]) { global $score; $score+= 10; global $bank3; $bank3[3] = false; } switch ($i = getRandom()) { case $i <= 40; bumper1(); break; case $i <= 80: bumper2(); break; case $i <= 95: flipper(); break; default: hole(); break; } break; case $i <= 80: if ($bank3[4]) { global $score; $score+= 10; global $bank3; $bank3[4] = false; } switch ($i = getRandom()) { case $i <= 40; bumper1(); break; case $i <= 80: bumper2(); break; case $i <= 95: flipper(); break; default: hole(); break; } break; case $i <= 96: if ($bank3[5]) { global $score; $score+= 10; global $bank3; $bank3[5] = false; } switch ($i = getRandom()) { case $i <= 40; bumper1(); break; case $i <= 80: bumper2(); break; case $i <= 95: flipper(); break; default: hole(); break; } break; case $i <= 99; flipper(); break; default: hole(); break; } } function bank4() { echo "<br />Bank 4 Hit!"; switch ($i = getRandom()) { case $i <= 16: if ($bank4[0]) { global $score; $score+= 10; global $bank4; $bank4[0] = false; } switch ($i = getRandom()) { case $i <= 40; bumper1(); break; case $i <= 80: bumper2(); break; case $i <= 95: flipper(); break; default: hole(); break; } break; case $i <= 32: if ($bank4[1]) { global $score; $score+= 10; global $bank4; $bank4[1] = false; } switch ($i = getRandom()) { case $i <= 40; bumper1(); break; case $i <= 80: bumper2(); break; case $i <= 95: flipper(); break; default: hole(); break; } break; case $i <= 48: if ($bank4[2]) { global $score; $score+= 10; global $bank4; $bank4[2] = false; } switch ($i = getRandom()) { case $i <= 40; bumper1(); break; case $i <= 80: bumper2(); break; case $i <= 95: flipper(); break; default: hole(); break; } break; case $i <= 64: if ($bank4[3]) { global $score; $score+= 10; global $bank4; $bank4[3] = false; } switch ($i = getRandom()) { case $i <= 40; bumper1(); break; case $i <= 80: bumper2(); break; case $i <= 95: flipper(); break; default: hole(); break; } break; case $i <= 80: if ($bank4[4]) { global $score; $score+= 10; global $bank4; $bank4[4] = false; } switch ($i = getRandom()) { case $i <= 40; bumper1(); break; case $i <= 80: bumper2(); break; case $i <= 95: flipper(); break; default: hole(); break; } break; case $i <= 96: if ($bank4[5]) { global $score; $score+= 10; global $bank4; $bank4[5] = false; } switch ($i = getRandom()) { case $i <= 40; bumper1(); break; case $i <= 80: bumper2(); break; case $i <= 95: flipper(); break; default: hole(); break; } break; case $i <= 99; flipper(); break; default: hole(); break; } } function flipper() { switch ($i = $skillLevel * getRandom()) { case $i <= 10: hole(); break; case $i <= 15: bank3(); break; case $i <= 20: bank4(); break; case $i <= 25: bank1(); break; case $i <= 30: bank2(); break; case $i <= 47: bumper1(); break; case $i <= 64: bumper2(); break; case $i <= 81: bumper3(); Similar TutorialsHi, I am using Snoopy class to read contents of a web page. But it doesn't perfectly simulate the browser because the content of web page changes when I use Snoopy to fetch it. And if I view it in browser directly then content is different. I even set the user agent string in Snoopy but still no luck. How can we perfectly simulate browser so it is indistinguishable whether we are using some script or a browser to view web page? Thanks |