Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <fstream>
- #include <vector>
- #include <ctime>
- #include <cstdlib>
- #include <limits>
- using namespace std;
- //fparam_ pre-fix is used for all variables used in function
- //prototypes
- class Player
- {
- public:
- Player()
- {
- difficulty = new int[3];
- }
- ~Player()
- {
- delete difficulty;
- }
- void gameStart();
- void save();
- void load();
- void startup();
- int mainGame();
- void accountNumbers();
- void shop();
- void cheats();
- void playerInfo();
- void getRandBankInfo();
- void findBank();
- private:
- int money;
- string name; //The player will enter their name so name will not be constant
- bool isFirstStartup;
- vector<string> createNumberList;
- vector<string> plr_inventory;
- vector<string> bankList;
- int experience;
- int *difficulty;
- int accountsHacked;
- int PasswordCrackerLvl;
- int DecryptionToolLvl;
- int PasswordCrackerPrice;
- int DecryptionToolPrice;
- };
- //Cheats for the player
- void Player::cheats()
- {
- string enterCheat;
- cin.ignore(numeric_limits<streamsize>::max(), '\n');
- cout << "Please enter your cheat here" << endl;
- getline(cin ,enterCheat);
- if(enterCheat == "give $100,000")
- {
- cout << "$100,000 added to bank account." << endl;
- money += 100000;
- }
- }
- //Loads everything if there is anything
- //If there is the game will continue to
- //the main game, if not it will run the
- //first startup to get basic information
- void Player::startup()
- {
- load();
- if(isFirstStartup == true)
- {
- gameStart();
- }
- if(isFirstStartup == false)
- {
- mainGame();
- }
- }
- //This is run when the player first plays the game.
- //If they have played the game before a variable
- //called isFirstStartup will be saved as false so
- //The game will skip this step as we dont want the
- //user to see the beginning startup dialog again
- void Player::gameStart()
- {
- cout << "Welcome to the game we are pleased to see a new" << endl;
- cout << "recruit join our ranks. We have a special mission" << endl;
- cout << "for you, we need you to hack into bank accounts all" << endl;
- cout << "across the world and take them for everything they have!" << endl;
- cout << "Now please enter your name" << endl;
- getline(cin, name);
- cout << "\nOk " << name << " were going to start you" << endl;
- cout << "off with $1200.\n" << endl;
- //Setting variables so they dont appear as long strange
- //Numbers when you view them in Stats.
- money = 1200;
- accountsHacked = 0;
- experience = 0;
- PasswordCrackerLvl = 1;
- DecryptionToolLvl = 1;
- cout << "Dont forget to save from the main menu or else your progress" << endl;
- cout << "will not be saved!!" << endl;
- cin.get();
- cin.clear();
- mainGame();
- }
- //This is the shop where the player can buy items
- //for use when they hack.
- void Player::shop()
- {
- bool shopLoopEnd = false;
- int local_shopChoice;
- PasswordCrackerPrice = 1000;
- DecryptionToolPrice = 1500;
- while(shopLoopEnd != true)
- {
- cout << "SHOP\n" << endl;
- cout << "What do you want to buy" << endl;
- cout << "1) Password Cracking Tool level " << PasswordCrackerLvl << " $" << PasswordCrackerPrice << endl;
- cout << "2) Decryption Tool level " << DecryptionToolLvl << " $" << DecryptionToolPrice << endl;
- cout << "3) Exit Shop" << endl;
- cin >> local_shopChoice;
- switch(local_shopChoice)
- {
- case 1:
- if(money >= PasswordCrackerPrice)
- {
- if(PasswordCrackerLvl < 5)
- {
- cout << "\nPassword Cracking Tool Purchased!\n" << endl;
- money -= 1000;
- PasswordCrackerLvl++;
- PasswordCrackerPrice += 1000;
- }
- if(PasswordCrackerLvl == 5)
- {
- cout << "\nCannot upgrade any higher!!\n" << endl;
- }
- save();
- }
- else if(money < PasswordCrackerPrice)
- {
- cout << "\nYou dont have enough money for that\n" << endl;
- }
- break;
- case 2:
- if(money >= DecryptionToolPrice)
- {
- if(DecryptionToolLvl < 5)
- {
- cout << "\nDecryption Tool Purchased!\n" << endl;
- money -= 1500;
- DecryptionToolLvl++;
- DecryptionToolPrice += 1500;
- }
- if(DecryptionToolLvl == 5)
- {
- cout << "\nCannot upgrade any higher!!\n" << endl;
- }
- save();
- }
- else if(money < DecryptionToolPrice)
- {
- cout << "\nYou dont have enough money for that\n" << endl;
- }
- break;
- case 3:
- shopLoopEnd = true;
- break;
- default:
- cin.clear();
- cin.ignore(numeric_limits<streamsize>::max(), '\n');
- }
- }
- cin.clear();
- cin.ignore(numeric_limits<streamsize>::max(), '\n');
- cout << '\n';
- }
- //this shows when you lose the game, it also removes your progress
- void gameLose()
- {
- cout << "You were caught!! you lose your account," << endl;
- cout << "your money, your items and you have gone to" << endl;
- cout << "prison for hacking and multiple other crimes!!!" << endl;
- remove("game.txt");
- }
- //This function loads the account numbers line by line
- //from the text document and stores them in a vector
- void Player::accountNumbers()
- {
- ifstream getPhoneNumbers;
- string getNumbers;
- getPhoneNumbers.open("account numbers.txt");
- if(getPhoneNumbers.is_open())
- {
- while(!getPhoneNumbers.eof())
- {
- getline(getPhoneNumbers, getNumbers);
- createNumberList.push_back(getNumbers);
- }
- }
- //Debug code
- for(size_t i = 0; i < createNumberList.size(); i++)
- {
- cout << createNumberList[i] << endl;
- }
- //End of debug code
- }
- void Player::save()
- {
- ofstream saveGame;
- saveGame.open("game.txt");
- isFirstStartup = false;
- saveGame << name << endl;
- saveGame << money << endl;
- saveGame << isFirstStartup << endl;
- saveGame << experience << endl;
- saveGame << accountsHacked << endl;
- saveGame << PasswordCrackerLvl << endl;
- saveGame << DecryptionToolLvl << endl;
- }
- void Player::load()
- {
- ifstream loadGame;
- loadGame.open("game.txt");
- if(loadGame.fail())
- {
- isFirstStartup = true;
- }
- getline(loadGame, name);
- loadGame >> money;
- loadGame >> isFirstStartup;
- loadGame >> experience;
- loadGame >> accountsHacked;
- loadGame >> PasswordCrackerLvl;
- loadGame >> DecryptionToolLvl;
- }
- int main()
- {
- Player p;
- p.startup();
- return 0;
- }
- void Player::playerInfo()
- {
- cout << '\n';
- cout << "Stats for: " << name << endl;
- cout << '\n';
- cout << "Total XP: " << experience << endl;
- cout << "Bank Accounts Hacked: " << accountsHacked << endl;
- cout << "Money in Bank Account $" << money << endl;
- //Debug lines
- //cout << "Decryption Tool Level " << DecryptionToolLvl << endl;
- //cout << "Password Cracker Level " << PasswordCrackerLvl << endl;
- cout << '\n';
- }
- void Player::getRandBankInfo()
- {
- //srand((unsigned)time(NULL));
- ifstream getBankList;
- string bankNames;
- getBankList.open("Bank List.txt");
- if(getBankList.is_open())
- {
- while(!getBankList.eof())
- {
- getline(getBankList, bankNames);
- bankList.push_back(bankNames);
- }
- }
- /*TODO
- //Write code to choose 5 random banks from the list
- //Each should have a difficulty based on the players
- //Experience level.
- */
- //The code below
- for(int i = 0; i < 49; i++)
- {
- //cout << bankList[rand() % bankList.size()] << endl;
- cout << bankList[i] << endl;
- }
- //=======================================================
- //Difficulty
- //=======================================================
- difficulty[3] = {1,2,3};
- }
- void Player::findBank()
- {
- int bankChoice;
- cout << "Here are a list of banks, choose wisely or you could" << endl;
- cout << "go to prison!!!\n" << endl;
- getRandBankInfo();
- cin >> bankChoice;
- /*TODO
- //let player choose from the list and also show the difficulty of
- //The hack so the player wont pick a hard one by accident and go
- //to jail.
- */
- cout << '\n';
- }
- void gameInfo()
- {
- cout << "\nVERSION 1.0 Alpha" << endl;
- cout << "Lines of Code - 420" << endl;
- cout << "Creator: Chay Hawk\n" << endl;
- cout << "Compiled and released on: UNKNOWN" << endl;
- }
- //This is the main game function where everything takes place
- //local_choice is a variable that will never leave the function
- int Player::mainGame()
- {
- vector<string> accountNumberList;
- int local_choice;
- bool endloop = false;
- while(endloop != true)
- {
- cout << "Main game" << endl;
- cout << "1) Store" << endl;
- cout << "2) Stats" << endl;
- cout << "3) Find bank" << endl;
- cout << "4) Save Game" << endl;
- cout << "5) Game Info" << endl;
- cout << "6) Exit" << endl;
- cin >> local_choice;
- switch(local_choice)
- {
- case 1:
- shop();
- break;
- case 2:
- playerInfo();
- break;
- case 3:
- findBank();
- break;
- case 4:
- save();
- break;
- case 5:
- gameInfo();
- break;
- case 6:
- endloop = true;
- break;
- case 5721:
- cheats();
- break;
- default:
- cout << "\nNot a valid input\n" << endl;
- cin.clear(); //Reset Error Flags
- cin.ignore(numeric_limits<streamsize>::max(), '\n');
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment