CH1156

HAcking Game

Aug 26th, 2013
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 10.70 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4. #include <vector>
  5. #include <ctime>
  6. #include <cstdlib>
  7. #include <limits>
  8.  
  9. using namespace std;
  10.  
  11. //fparam_ pre-fix is used for all variables used in function
  12. //prototypes
  13.  
  14. class Player
  15. {
  16.     public:
  17.         Player()
  18.         {
  19.             difficulty = new int[3];
  20.         }
  21.         ~Player()
  22.         {
  23.             delete difficulty;
  24.         }
  25.         void gameStart();
  26.         void save();
  27.         void load();
  28.         void startup();
  29.         int mainGame();
  30.         void accountNumbers();
  31.         void shop();
  32.         void cheats();
  33.         void playerInfo();
  34.         void getRandBankInfo();
  35.         void findBank();
  36.  
  37.     private:
  38.         int money;
  39.         string name; //The player will enter their name so name will not be constant
  40.         bool isFirstStartup;
  41.         vector<string> createNumberList;
  42.         vector<string> plr_inventory;
  43.         vector<string> bankList;
  44.         int experience;
  45.         int *difficulty;
  46.         int accountsHacked;
  47.         int PasswordCrackerLvl;
  48.         int DecryptionToolLvl;
  49.         int PasswordCrackerPrice;
  50.         int DecryptionToolPrice;
  51. };
  52.  
  53. //Cheats for the player
  54.  
  55. void Player::cheats()
  56. {
  57.     string enterCheat;
  58.     cin.ignore(numeric_limits<streamsize>::max(), '\n');
  59.  
  60.     cout << "Please enter your cheat here" << endl;
  61.     getline(cin ,enterCheat);
  62.  
  63.     if(enterCheat == "give $100,000")
  64.     {
  65.         cout << "$100,000 added to bank account." << endl;
  66.         money += 100000;
  67.     }
  68. }
  69.  
  70. //Loads everything if there is anything
  71. //If there is the game will continue to
  72. //the main game, if not it will run the
  73. //first startup to get basic information
  74.  
  75. void Player::startup()
  76. {
  77.     load();
  78.  
  79.     if(isFirstStartup == true)
  80.     {
  81.         gameStart();
  82.     }
  83.     if(isFirstStartup == false)
  84.     {
  85.         mainGame();
  86.     }
  87. }
  88.  
  89. //This is run when the player first plays the game.
  90. //If they have played the game before a variable
  91. //called isFirstStartup will be saved as false so
  92. //The game will skip this step as we dont want the
  93. //user to see the beginning startup dialog again
  94.  
  95. void Player::gameStart()
  96. {
  97.     cout << "Welcome to the game we are pleased to see a new" << endl;
  98.     cout << "recruit join our ranks. We have a special mission" << endl;
  99.     cout << "for you, we need you to hack into bank accounts all" << endl;
  100.     cout << "across the world and take them for everything they have!" << endl;
  101.  
  102.     cout << "Now please enter your name" << endl;
  103.     getline(cin, name);
  104.  
  105.     cout << "\nOk " << name << " were going to start you" << endl;
  106.     cout << "off with $1200.\n" << endl;
  107.  
  108.     //Setting variables so they dont appear as long strange
  109.     //Numbers when you view them in Stats.
  110.  
  111.     money = 1200;
  112.     accountsHacked = 0;
  113.     experience = 0;
  114.     PasswordCrackerLvl = 1;
  115.     DecryptionToolLvl = 1;
  116.  
  117.     cout << "Dont forget to save from the main menu or else your progress" << endl;
  118.     cout << "will not be saved!!" << endl;
  119.     cin.get();
  120.     cin.clear();
  121.  
  122.     mainGame();
  123. }
  124.  
  125. //This is the shop where the player can buy items
  126. //for use when they hack.
  127.  
  128. void Player::shop()
  129. {
  130.     bool shopLoopEnd = false;
  131.     int local_shopChoice;
  132.     PasswordCrackerPrice = 1000;
  133.     DecryptionToolPrice = 1500;
  134.  
  135.     while(shopLoopEnd != true)
  136.     {
  137.         cout << "SHOP\n" << endl;
  138.  
  139.         cout << "What do you want to buy" << endl;
  140.         cout << "1) Password Cracking Tool level " << PasswordCrackerLvl << " $" << PasswordCrackerPrice << endl;
  141.         cout << "2) Decryption Tool level " << DecryptionToolLvl << " $" << DecryptionToolPrice << endl;
  142.         cout << "3) Exit Shop" << endl;
  143.         cin >> local_shopChoice;
  144.  
  145.         switch(local_shopChoice)
  146.         {
  147.             case 1:
  148.                 if(money >= PasswordCrackerPrice)
  149.                 {
  150.                     if(PasswordCrackerLvl < 5)
  151.                     {
  152.                         cout << "\nPassword Cracking Tool Purchased!\n" << endl;
  153.                         money -= 1000;
  154.                         PasswordCrackerLvl++;
  155.                         PasswordCrackerPrice += 1000;
  156.                     }
  157.                     if(PasswordCrackerLvl == 5)
  158.                     {
  159.                         cout << "\nCannot upgrade any higher!!\n" << endl;
  160.                     }
  161.  
  162.                     save();
  163.                 }
  164.                 else if(money < PasswordCrackerPrice)
  165.                 {
  166.                     cout << "\nYou dont have enough money for that\n" << endl;
  167.                 }
  168.                 break;
  169.  
  170.             case 2:
  171.                 if(money >= DecryptionToolPrice)
  172.                 {
  173.                     if(DecryptionToolLvl < 5)
  174.                     {
  175.                         cout << "\nDecryption Tool Purchased!\n" << endl;
  176.                         money -= 1500;
  177.                         DecryptionToolLvl++;
  178.                         DecryptionToolPrice += 1500;
  179.                     }
  180.                     if(DecryptionToolLvl == 5)
  181.                     {
  182.                         cout << "\nCannot upgrade any higher!!\n" << endl;
  183.                     }
  184.  
  185.                     save();
  186.                 }
  187.                 else if(money < DecryptionToolPrice)
  188.                 {
  189.                     cout << "\nYou dont have enough money for that\n" << endl;
  190.                 }
  191.                 break;
  192.  
  193.             case 3:
  194.                 shopLoopEnd = true;
  195.                 break;
  196.  
  197.             default:
  198.                 cin.clear();
  199.                 cin.ignore(numeric_limits<streamsize>::max(), '\n');
  200.         }
  201.     }
  202.     cin.clear();
  203.     cin.ignore(numeric_limits<streamsize>::max(), '\n');
  204.     cout << '\n';
  205. }
  206.  
  207. //this shows when you lose the game, it also removes your progress
  208.  
  209. void gameLose()
  210. {
  211.     cout << "You were caught!! you lose your account," << endl;
  212.     cout << "your money, your items and you have gone to" << endl;
  213.     cout << "prison for hacking and multiple other crimes!!!" << endl;
  214.  
  215.     remove("game.txt");
  216. }
  217.  
  218. //This function loads the account numbers line by line
  219. //from the text document and stores them in a vector
  220.  
  221. void Player::accountNumbers()
  222. {
  223.     ifstream getPhoneNumbers;
  224.     string getNumbers;
  225.  
  226.     getPhoneNumbers.open("account numbers.txt");
  227.  
  228.     if(getPhoneNumbers.is_open())
  229.     {
  230.         while(!getPhoneNumbers.eof())
  231.         {
  232.             getline(getPhoneNumbers, getNumbers);
  233.             createNumberList.push_back(getNumbers);
  234.         }
  235.     }
  236.  
  237.     //Debug code
  238.     for(size_t i = 0; i < createNumberList.size(); i++)
  239.     {
  240.         cout << createNumberList[i] << endl;
  241.     }
  242.     //End of debug code
  243. }
  244.  
  245. void Player::save()
  246. {
  247.     ofstream saveGame;
  248.     saveGame.open("game.txt");
  249.  
  250.     isFirstStartup = false;
  251.  
  252.     saveGame << name << endl;
  253.     saveGame << money << endl;
  254.     saveGame << isFirstStartup << endl;
  255.     saveGame << experience << endl;
  256.     saveGame << accountsHacked << endl;
  257.     saveGame << PasswordCrackerLvl << endl;
  258.     saveGame << DecryptionToolLvl << endl;
  259. }
  260.  
  261. void Player::load()
  262. {
  263.     ifstream loadGame;
  264.     loadGame.open("game.txt");
  265.  
  266.     if(loadGame.fail())
  267.     {
  268.         isFirstStartup = true;
  269.     }
  270.  
  271.     getline(loadGame, name);
  272.     loadGame >> money;
  273.     loadGame >> isFirstStartup;
  274.     loadGame >> experience;
  275.     loadGame >> accountsHacked;
  276.     loadGame >> PasswordCrackerLvl;
  277.     loadGame >> DecryptionToolLvl;
  278. }
  279.  
  280. int main()
  281. {
  282.     Player p;
  283.     p.startup();
  284.  
  285.     return 0;
  286. }
  287.  
  288. void Player::playerInfo()
  289. {
  290.     cout << '\n';
  291.  
  292.     cout << "Stats for: " << name << endl;
  293.  
  294.     cout << '\n';
  295.     cout << "Total XP: " << experience << endl;
  296.     cout << "Bank Accounts Hacked: " << accountsHacked << endl;
  297.     cout << "Money in Bank Account $" << money << endl;
  298.     //Debug lines
  299.     //cout << "Decryption Tool Level " << DecryptionToolLvl << endl;
  300.     //cout << "Password Cracker Level " << PasswordCrackerLvl << endl;
  301.     cout << '\n';
  302. }
  303.  
  304. void Player::getRandBankInfo()
  305. {
  306.     //srand((unsigned)time(NULL));
  307.     ifstream getBankList;
  308.     string bankNames;
  309.  
  310.     getBankList.open("Bank List.txt");
  311.  
  312.     if(getBankList.is_open())
  313.     {
  314.         while(!getBankList.eof())
  315.         {
  316.             getline(getBankList, bankNames);
  317.             bankList.push_back(bankNames);
  318.         }
  319.     }
  320.  
  321.     /*TODO
  322.     //Write code to choose 5 random banks from the list
  323.     //Each should have a difficulty based on the players
  324.     //Experience level.
  325.     */
  326.  
  327.     //The code below
  328.     for(int i = 0; i < 49; i++)
  329.     {
  330.         //cout << bankList[rand() % bankList.size()] << endl;
  331.         cout <<  bankList[i] << endl;
  332.     }
  333.  
  334.     //=======================================================
  335.     //Difficulty
  336.     //=======================================================
  337.  
  338.     difficulty[3] = {1,2,3};
  339. }
  340.  
  341. void Player::findBank()
  342. {
  343.     int bankChoice;
  344.  
  345.     cout << "Here are a list of banks, choose wisely or you could" << endl;
  346.     cout << "go to prison!!!\n" << endl;
  347.  
  348.     getRandBankInfo();
  349.  
  350.     cin >> bankChoice;
  351.  
  352.     /*TODO
  353.     //let player choose from the list and also show the difficulty of
  354.     //The hack so the player wont pick a hard one by accident and go
  355.     //to jail.
  356.     */
  357.  
  358.     cout << '\n';
  359. }
  360.  
  361. void gameInfo()
  362. {
  363.     cout << "\nVERSION 1.0 Alpha" << endl;
  364.     cout << "Lines of Code - 420" << endl;
  365.     cout << "Creator: Chay Hawk\n" << endl;
  366.     cout << "Compiled and released on: UNKNOWN" << endl;
  367. }
  368.  
  369. //This is the main game function where everything takes place
  370. //local_choice is a variable that will never leave the function
  371.  
  372. int Player::mainGame()
  373. {
  374.     vector<string> accountNumberList;
  375.  
  376.     int local_choice;
  377.     bool endloop = false;
  378.  
  379.     while(endloop != true)
  380.     {
  381.         cout << "Main game" << endl;
  382.         cout << "1) Store" << endl;
  383.         cout << "2) Stats" << endl;
  384.         cout << "3) Find bank" << endl;
  385.         cout << "4) Save Game" << endl;
  386.         cout << "5) Game Info" << endl;
  387.         cout << "6) Exit" << endl;
  388.         cin >> local_choice;
  389.  
  390.         switch(local_choice)
  391.         {
  392.             case 1:
  393.                 shop();
  394.                 break;
  395.             case 2:
  396.                 playerInfo();
  397.                 break;
  398.             case 3:
  399.                 findBank();
  400.                 break;
  401.             case 4:
  402.                 save();
  403.                 break;
  404.             case 5:
  405.                 gameInfo();
  406.                 break;
  407.             case 6:
  408.                 endloop = true;
  409.                 break;
  410.             case 5721:
  411.                 cheats();
  412.                 break;
  413.             default:
  414.                 cout << "\nNot a valid input\n" << endl;
  415.                 cin.clear(); //Reset Error Flags
  416.                 cin.ignore(numeric_limits<streamsize>::max(), '\n');
  417.         }
  418.     }
  419.     return 0;
  420. }
Advertisement
Add Comment
Please, Sign In to add comment