Abdulg

Lobster pots game C++

Mar 29th, 2012
403
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.12 KB | None | 0 0
  1. #include<iostream>
  2. #include<time.h>
  3. #include<cstdlib>
  4. #include<fstream>
  5. using namespace std;
  6.  
  7. int Chance, YN, Money, LobsterPots, Inshore, Outshore, Profit, Buying, HMoney;
  8. char Name[260], HName[260];
  9.  
  10.  
  11.  
  12. int main()
  13. {
  14.     Money = 50;
  15.     LobsterPots = 10;
  16.     srand ( time(NULL) );
  17.     ofstream FileO;
  18.     ifstream FileI;
  19.     FileI.open("HighScores.lob");
  20.     FileI >> HName >> HMoney;
  21.     FileI.close();
  22.     cout << "Insert your name:" << endl << "> ";
  23.     cin.getline(Name,260);
  24.     cout << endl << "Welcome to lobster pots, by Abdul Ghani. This is where you begin on your journey to become a lobster barron in just 7 days." << endl << "You start off with just $50 and 10 lobster pots. You can buy more throughout the course of the game. You can choose to place some inshore and some outshore. If you place them inshore, you are garanteed a return of $10. If you place them offshore, you get more money ($20) but if its stormy, you will lose them." << endl << "The chance of a storm if randomly generated. You are told of the chances before you decide." << endl << endl;
  25.     cout << endl << "The current high score holder is " << HName << " with $" << HMoney << endl;
  26.     for (int Days = 7; Days > 0; Days --)
  27.     {
  28.     Chance = rand ()  % 100 + 1;
  29.     YN = rand () % 100 + 1;
  30.     Choice:
  31.     cout << "You have " << Days << " days left." << endl;
  32.     cout << " You have $" << Money << " and " << LobsterPots << " lobster pots." << endl;
  33.     cout << "There is a " << Chance << "% chance of a storm today." << endl;
  34.     cout << "How many do you want to put inshore?" << endl << "> ";
  35.     cin >> Inshore;
  36.     cout << endl << "How many do you want to put outshore?" << endl << "> ";
  37.     cin >> Outshore;
  38.     if (Inshore + Outshore != LobsterPots)
  39.     {
  40.         cout << "Incorrect amount of lobster pots. Please try again." << endl << endl;
  41.         goto Choice;
  42.     }
  43.     if (YN <= Chance)
  44.     {
  45.         cout << "It was stormy! You lost " << Outshore << " pots." << endl;
  46.         LobsterPots = LobsterPots - Outshore;
  47.         Outshore = 0;
  48.     }
  49.     if (YN > Chance)
  50.     {
  51.         cout << "The weather was fine!" << endl;
  52.     }
  53.     Profit = (Inshore * 10) + (Outshore * 20);
  54.     Money = Money + Profit;
  55.     Buy:
  56.     cout << "You made $" << Profit << " during that round. Your total is $" << Money << endl;
  57.     cout << "You can buy lobster pots at $20 a pot." << endl;
  58.     cout << "How many would you like to buy?" << endl << "> ";
  59.     cin >> Buying;
  60.     if ((Buying * 20) > Money)
  61.     {
  62.         cout << "Sorry, but you don't have enough money to do that" << endl;
  63.         goto Buy;
  64.     }
  65.     Money = Money - (Buying * 20);
  66.     LobsterPots = LobsterPots + Buying;
  67.     cout << "You bought " << Buying << " pots for $" << Buying * 20 << ". You have $" << Money << " left, and "<< LobsterPots << " pots." << endl;
  68.     }
  69.     cout << "Thats your week! Your pots will sell for $5 each, which gives you $" << LobsterPots * 5 << endl;
  70.     Money = Money + (LobsterPots * 5);
  71.     cout << "You finish off with $" << Money << "." << endl;
  72.     if (Money > HMoney)
  73.     {
  74.         cout << endl << "You beat the high score!" << endl;
  75.         FileO.open("HighScores.lob");
  76.         FileO << Name << endl << Money;
  77.         FileO.close();
  78.     }
  79.     else
  80.     {
  81.         cout << endl << "Sorry, but you didn't beat the high score :(" << endl;
  82.     }
  83.  
  84.     system("PAUSE");
  85.     return 0; // done
  86. }
Advertisement
Add Comment
Please, Sign In to add comment