Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $cmdList = "[COMMANDS] /commands | /buy | /fitline | /fish | (/inv)entory | /startfishing | /stopfishing | /quitgame\n";
- echo "Welcome to the Bay! Purchase a rod and a small net otherwise you'll have to throw your fish back!\n";
- echo $cmdList;
- $fishingState = 0;
- $invRod = 0;
- $invNet = 0;
- $invLine = 0;
- $invLineStatus = 'off';
- $fishCount = 0;
- $fishWeight = 0;
- $fish = array('Shark','Silverfish','Swordfish','Bass','Catfish','Carp','Boga','Whale');
- // Fish Game - Until player enters /quitgame.
- do {
- $inventory = "[INVENTORY] $invRod FishingRod | $invLine FishingLine(s) | $invNet FishingNet | FishAmount: $fishCount | FishWeight: $fishWeight"."lbs\n";
- $userInput = readline();
- if ($userInput == '/commands' || $userInput == '/help' || $userInput == '/cmds') {
- echo $cmdList;
- }
- elseif ($userInput == '/buy') {
- if ($fishingState == 1) {
- echo "You can't visit the shop while you're fishing! (/stopfishing)\n";
- } else {
- echo "Welcome to Hank's Bait Shop! Available Items: Rod, Net, Line\n";
- echo "TIP: Use /buy itemname\n";
- }
- }
- elseif ($userInput == "/buy Rod" || $userInput == "/buy rod") {
- if ($fishingState == 1) {
- echo "You can't buy anything from the shop while you're fishing! (/stopfishing)\n";
- } else {
- if ($invRod == 1) {
- echo "You already have a rod!\n";
- } else {
- $invRod = 1;
- echo "You have purchased a Fishing Rod.\n";
- }
- }
- }
- elseif ($userInput == "/buy Net" || $userInput == "/buy net") {
- if ($fishingState == 1) {
- echo "You can't buy anything from the shop while you're fishing! (/stopfishing)\n";
- } else {
- if ($invNet == 1) {
- echo "You already have a net!\n";
- } else {
- $invNet = 1;
- echo "You have purchased a Fishing Net.\n";
- }
- }
- }
- elseif ($userInput == "/buy Line" || $userInput == "/buy line") {
- if ($fishingState == 1) {
- echo "You can't buy anything from the shop while you're fishing! (/stopfishing)\n";
- } else {
- $invLine++;
- echo "You have purchased a Fishing Line. You have $invLine Fishing Line(s).\n";
- }
- }
- elseif ($userInput == "/fitline") {
- if ($invLineStatus == 'on') {
- echo "You already have a line attached!\n";
- } elseif ($invLine == 0) {
- echo "You haven't got any more lines!\n";
- } else {
- $invLine--;
- $invLineStatus = 'on';
- echo "You have fitted a new line on your rod. You have $invLine Line(s) left!\n";
- }
- }
- elseif ($userInput == "/inventory" || $userInput == "/inv") {
- echo $inventory;
- }
- elseif ($userInput == "/startfishing") {
- $fishingState = 1;
- echo "You are now fishing. Use /fish or you can /stopfishing at any time.\n";
- if ($invNet == 0) {
- echo "You haven't purchased a fishing net. Purchase one if you wish to store caught fish!\n";
- }
- }
- elseif ($userInput == "/stopfishing") {
- $fishingState = 0;
- echo "You have stopped fishing. Use /startfishing at any time.\n";
- }
- elseif ($userInput == "/fish") { // Begin fishing script.
- if ($fishingState == 1) {
- if ($invRod == 0) {
- echo "You must purchase a rod to begin fishing!\n";
- }
- if ($invLineStatus == 'off') {
- echo "A line isn't fitted to the rod. (/fitline)\n";
- }
- if ($invLine == 0 && $invLineStatus == 'off') {
- echo "You need to purchase some lines for your rod.\n";
- }
- if ($invRod == 1 && $invLineStatus == 'on') {
- $fishSuccess = rand(1,10);
- if ($fishSuccess == 9) { // Line Snapped
- echo "The line snapped! You'll have to fit another on!\n";
- $invLineStatus = 'off';
- }
- elseif ($fishSuccess == 10) { // No Catch
- echo "You failed to catch anything!\n";
- } else {
- $fish_rand = array_rand($fish, 1);
- $weight = rand(4,80);
- echo "You have caught a $fish[$fish_rand] weighing $weight"."lbs!\n";
- if ($invNet == 1) {
- echo "Would you like to keep it or throw it back? [/keep] [/throw]\n";
- $storePrompt = readline();
- if ($storePrompt == '/keep') {
- $fishWeight = $fishWeight + $weight;
- $fishCount++;
- echo "You have chosen to keep the $fish[$fish_rand]!\n";
- }
- elseif ($storePrompt == '/throw') {
- echo "You threw the $fish[$fish_rand] back!\n";
- } else {
- echo "Unknown command. The $fish[$fish_rand] has automatically been thrown back to live with it's family.\n";
- }
- } else {
- echo "You threw it back as you haven't got a net to store it in!\n";
- }
- }
- }
- } else {
- echo "You are not fishing. Use /startfishing to begin. (/commands for help)\n";
- }
- }
- else {
- echo "Unknown command. Please refer to /commands or you can /quitgame.\n";
- }
- } while ($userInput !== '/quitgame');
- echo "You have quit the game. Would you like to save your stats? (Y/y) to save or anything else to not save.\n";
- $saveConfirm = readline();
- if ($saveConfirm == 'Y' || $saveConfirm == 'y') {
- file_put_contents('fishdata.txt', $inventory);
- echo "Your data has been saved, overwriting the file 'fishdata.txt'. Thanks for playing!\n";
- } else {
- echo "Your data has not been saved. Thanks for playing!\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement