Advertisement
fidle89

PHP Fishing Script

Jan 24th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.09 KB | None | 0 0
  1. <?php
  2.  
  3. $cmdList = "[COMMANDS] /commands | /buy | /fitline | /fish | (/inv)entory | /startfishing | /stopfishing | /quitgame\n";
  4.  
  5. echo "Welcome to the Bay! Purchase a rod and a small net otherwise you'll have to throw your fish back!\n";
  6. echo $cmdList;
  7.  
  8. $fishingState = 0;
  9. $invRod = 0;
  10. $invNet = 0;
  11. $invLine = 0;
  12. $invLineStatus = 'off';
  13. $fishCount = 0;
  14. $fishWeight = 0;
  15.  
  16. $fish = array('Shark','Silverfish','Swordfish','Bass','Catfish','Carp','Boga','Whale');
  17.  
  18. // Fish Game - Until player enters /quitgame.
  19. do {
  20.  
  21.     $inventory = "[INVENTORY] $invRod FishingRod | $invLine FishingLine(s) | $invNet FishingNet | FishAmount: $fishCount | FishWeight: $fishWeight"."lbs\n";
  22.  
  23.     $userInput = readline();
  24.  
  25.     if ($userInput == '/commands' || $userInput == '/help' || $userInput == '/cmds') {
  26.         echo $cmdList;
  27.     }
  28.     elseif ($userInput == '/buy') {
  29.         if ($fishingState == 1) {
  30.             echo "You can't visit the shop while you're fishing! (/stopfishing)\n";
  31.         } else {
  32.             echo "Welcome to Hank's Bait Shop! Available Items: Rod, Net, Line\n";
  33.             echo "TIP: Use /buy itemname\n";
  34.         }
  35.     }
  36.     elseif ($userInput == "/buy Rod" || $userInput == "/buy rod") {
  37.         if ($fishingState == 1) {
  38.             echo "You can't buy anything from the shop while you're fishing! (/stopfishing)\n";
  39.         } else {
  40.             if ($invRod == 1) {
  41.                 echo "You already have a rod!\n";
  42.             } else {
  43.                 $invRod = 1;
  44.                 echo "You have purchased a Fishing Rod.\n";
  45.             }
  46.         }
  47.     }
  48.     elseif ($userInput == "/buy Net" || $userInput == "/buy net") {
  49.         if ($fishingState == 1) {
  50.             echo "You can't buy anything from the shop while you're fishing! (/stopfishing)\n";
  51.         } else {
  52.             if ($invNet == 1) {
  53.                 echo "You already have a net!\n";
  54.             } else {
  55.                 $invNet = 1;
  56.                 echo "You have purchased a Fishing Net.\n";
  57.             }
  58.         }
  59.     }
  60.     elseif ($userInput == "/buy Line" || $userInput == "/buy line") {
  61.         if ($fishingState == 1) {
  62.             echo "You can't buy anything from the shop while you're fishing! (/stopfishing)\n";
  63.         } else {
  64.             $invLine++;
  65.             echo "You have purchased a Fishing Line. You have $invLine Fishing Line(s).\n";
  66.         }
  67.     }
  68.     elseif ($userInput == "/fitline") {
  69.         if ($invLineStatus == 'on') {
  70.             echo "You already have a line attached!\n";
  71.         } elseif ($invLine == 0) {
  72.             echo "You haven't got any more lines!\n";
  73.         } else {
  74.             $invLine--;
  75.             $invLineStatus = 'on';
  76.             echo "You have fitted a new line on your rod. You have $invLine Line(s) left!\n";
  77.         }
  78.     }
  79.     elseif ($userInput == "/inventory" || $userInput == "/inv") {
  80.         echo $inventory;
  81.     }
  82.     elseif ($userInput == "/startfishing") {
  83.         $fishingState = 1;
  84.         echo "You are now fishing. Use /fish or you can /stopfishing at any time.\n";
  85.         if ($invNet == 0) {
  86.             echo "You haven't purchased a fishing net. Purchase one if you wish to store caught fish!\n";
  87.         }
  88.     }
  89.     elseif ($userInput == "/stopfishing") {
  90.         $fishingState = 0;
  91.         echo "You have stopped fishing. Use /startfishing at any time.\n";
  92.     }
  93.     elseif ($userInput == "/fish") { // Begin fishing script.
  94.  
  95.         if ($fishingState == 1) {
  96.  
  97.             if ($invRod == 0) {
  98.                 echo "You must purchase a rod to begin fishing!\n";
  99.             }
  100.             if ($invLineStatus == 'off') {
  101.                 echo "A line isn't fitted to the rod. (/fitline)\n";
  102.             }
  103.             if ($invLine == 0 && $invLineStatus == 'off') {
  104.                 echo "You need to purchase some lines for your rod.\n";
  105.             }
  106.             if ($invRod == 1 && $invLineStatus == 'on') {
  107.  
  108.                 $fishSuccess = rand(1,10);
  109.                 if ($fishSuccess == 9) { // Line Snapped
  110.                     echo "The line snapped! You'll have to fit another on!\n";
  111.                     $invLineStatus = 'off';
  112.                 }
  113.                 elseif ($fishSuccess == 10) { // No Catch
  114.                     echo "You failed to catch anything!\n";
  115.                 } else {
  116.                     $fish_rand = array_rand($fish, 1);
  117.                     $weight = rand(4,80);
  118.                     echo "You have caught a $fish[$fish_rand] weighing $weight"."lbs!\n";
  119.                     if ($invNet == 1) {
  120.                         echo "Would you like to keep it or throw it back? [/keep] [/throw]\n";
  121.                         $storePrompt = readline();
  122.                         if ($storePrompt == '/keep') {
  123.                             $fishWeight = $fishWeight + $weight;
  124.                             $fishCount++;
  125.                             echo "You have chosen to keep the $fish[$fish_rand]!\n";
  126.                         }
  127.                         elseif ($storePrompt == '/throw') {
  128.                             echo "You threw the $fish[$fish_rand] back!\n";
  129.                         } else {
  130.                             echo "Unknown command. The $fish[$fish_rand] has automatically been thrown back to live with it's family.\n";
  131.                         }
  132.                     } else {
  133.                         echo "You threw it back as you haven't got a net to store it in!\n";
  134.                     }
  135.                 }
  136.             }
  137.  
  138.         } else {
  139.             echo "You are not fishing. Use /startfishing to begin. (/commands for help)\n";
  140.         }
  141.  
  142.     }
  143.     else {
  144.         echo "Unknown command. Please refer to /commands or you can /quitgame.\n";
  145.     }
  146.  
  147.  
  148. } while ($userInput !== '/quitgame');
  149. echo "You have quit the game. Would you like to save your stats? (Y/y) to save or anything else to not save.\n";
  150. $saveConfirm = readline();
  151. if ($saveConfirm == 'Y' || $saveConfirm == 'y') {
  152.     file_put_contents('fishdata.txt', $inventory);
  153.     echo "Your data has been saved, overwriting the file 'fishdata.txt'. Thanks for playing!\n";
  154. } else {
  155.     echo "Your data has not been saved. Thanks for playing!\n";
  156. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement