Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Main.cpp
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <vector>
- #include <cstdlib>
- #include <ctime>
- #include <sstream>
- #include "player.h"
- #include "Dinosaur.h"
- #include "Prototypes.h"
- using namespace std;
- Player::Player(unsigned int PLAYERHEALTH, unsigned int PISTOLAMMO,
- unsigned int SHOTGUNAMMO, unsigned int RIFLEAMMO,
- unsigned int SCORE, unsigned int MONEY,
- unsigned int HEALTHPACKS, int TURNS, std::vector<int> ITEMS): playerHealth(PLAYERHEALTH),
- pistolAmmo(PISTOLAMMO),
- shotgunAmmo(SHOTGUNAMMO),
- rifleAmmo(RIFLEAMMO),
- score(SCORE),
- money(MONEY),
- healthPacks(HEALTHPACKS),
- turns(TURNS)
- {
- }
- Dinosaur::Dinosaur(int DINOSAURHEALTH, int ATTACKS, time_t CREATETIME): dinosaurHealth(DINOSAURHEALTH),
- attacks(ATTACKS),
- createTime(CREATETIME)
- {
- }
- /*
- ==================|
- Main Menu function|
- ==================|
- */
- int Menu(Player &player, Dinosaur &dinosaur)
- {
- int intChoice;
- string strChoice;
- cout << "Build 1.2.0" << endl;
- cout << "\n";
- cout << "DINOSAUR ARENA\n" << endl;
- cout << "What do you want to do?\n" << endl;
- cout << "1) Load Game" << endl;
- cout << "2) New Game" << endl;
- cout << "3) Game Info" << endl;
- cout << "4) Quit Game" << endl;
- do
- {
- stringstream ss; //Why does this need to be in the loop for the stringstream to work?
- //Without it, the program will not convert the string to int.
- getline(cin, strChoice);
- ss << strChoice;
- ss >> intChoice;
- //Debug
- cout << "strChoice: " << strChoice << endl;
- cout << "intChoice: " << intChoice << endl;
- //End Debug
- switch(intChoice)
- {
- case 1:
- load(player, dinosaur);
- break;
- case 2:
- MainGame(player, dinosaur);
- break;
- case 3:
- gameInfo();
- break;
- case 4:
- return 0;
- break;
- default:
- cout << "Error" << endl;
- break;
- }
- }
- while(intChoice != -1);
- }
- /*
- =============|
- Save function|
- =============|
- */
- void save(Player &player, Dinosaur &dinosaur)
- {
- ofstream fileOut;
- fileOut.open("DASave.txt");
- fileOut << player.playerHealth << endl;
- fileOut << player.pistolAmmo << endl;
- fileOut << player.shotgunAmmo << endl;
- fileOut << player.rifleAmmo << endl;
- fileOut << player.score << endl;
- fileOut << player.money << endl;
- fileOut << player.healthPacks << endl;
- MainGame(player, dinosaur);
- }
- /*
- =============|
- Load function|
- =============|
- */
- void load(Player &player, Dinosaur &dinosaur)
- {
- //TODO
- //Add error checking for loading function
- ifstream fileIn;
- fileIn.open("DASave.txt");
- fileIn >> player.playerHealth;
- fileIn >> player.pistolAmmo;
- fileIn >> player.shotgunAmmo;
- fileIn >> player.rifleAmmo;
- fileIn >> player.score;
- fileIn >> player.money;
- fileIn >> player.healthPacks;
- cout << "Health: " << player.playerHealth << endl;
- cout << "Pistol Ammo: " << player.pistolAmmo << endl;
- cout << "Shotgun Ammo: " << player.shotgunAmmo << endl;
- cout << "Rifle Ammo: " << player.rifleAmmo << endl;
- cout << "Score: " << player.score << endl;
- cout << "player.money: " << player.money << endl;
- cout << "Health Packs: " << player.healthPacks << endl;
- cout << "\n";
- MainGame(player, dinosaur);
- }
- /*
- =============|
- Shop function|
- =============|
- */
- void shop(Player &player, Dinosaur &dinosaur)
- {
- unsigned int menuChoice;
- int amountChoice = 0;
- unsigned int itemPrice;
- unsigned int itemQuantity = 0;
- unsigned int confirmPurchase;
- string itemName;
- string itemType;
- while((amountChoice != -1) || (menuChoice != -1))
- {
- cout << "\n";
- cout << "GENERAL STORE\n" << endl;
- cout << "Type in -1 to quit" << endl;
- cout << "1) Health Pack - $5" << endl;
- cout << "2) Pistol Ammo - $2" << endl;
- cout << "3) Shotgun Ammo - $5" << endl;
- cout << "4) Rifle Ammo - $18" << endl;
- cin >> menuChoice;
- if((amountChoice == -1) || (menuChoice == -1))
- {
- cout << "Thank you for shopping at the store\n" << endl;
- MainGame(player, dinosaur);
- break;
- }
- else
- {
- switch(menuChoice)
- {
- case 1:
- {
- cout << "You get 1 Health Pack per purchase" << endl;
- itemName = "Health Pack(s)";
- itemType = "Unit(s)";
- itemPrice = 5;
- itemQuantity = 1;
- }break;
- case 2:
- {
- cout << "You get 17 rounds of Pistol Ammo per purchase" << endl;
- itemName = "Pistol Ammo";
- itemType = "Round(s)";
- itemPrice = 2;
- itemQuantity = 17;
- }break;
- case 3:
- {
- cout << "You get 8 rounds of Shotgun Ammo per purchase" << endl;
- itemName = "Shotgun Ammo";
- itemType = "Round(s)";
- itemPrice = 5;
- itemQuantity = 8;
- }break;
- case 4:
- {
- cout << "You get 14 rounds of Rifle Ammo per purchase" << endl;
- itemName = "Rifle Ammo";
- itemType = "Round(s)";
- itemPrice = 18;
- itemQuantity = 14;
- }break;
- default:
- cout << "Invalid answer" << endl;
- }
- cout << "How many do you want to buy?" << endl;
- while(amountChoice != -1)
- {
- cin >> amountChoice;
- if(player.money >= amountChoice * itemPrice)
- {
- cout << "Are you sure you want to buy " << amountChoice * itemQuantity << " " << itemType << " of " << itemName << endl;
- cout << "This will cost $" << amountChoice * itemPrice << endl;
- cout << "Type in 1 for YES and 2 for NO" << endl;
- cin >> confirmPurchase;
- if(confirmPurchase == 1)
- {
- player.money -= amountChoice * itemPrice;
- cout << "Thank you for your purchase: -$" << amountChoice * itemPrice << endl;
- cout << "You recieved +" << amountChoice * itemQuantity << " " << itemName << endl;
- //Add items to inventory
- switch(menuChoice)
- {
- case 1:{player.healthPacks += amountChoice * itemQuantity;}break;
- case 2:{player.pistolAmmo += amountChoice * itemQuantity;}break;
- case 3:{player.shotgunAmmo += amountChoice * itemQuantity;}break;
- case 4:{player.rifleAmmo += amountChoice * itemQuantity;}break;
- default: cout << "Error" << endl;
- }
- cout << "Your current money is $" << player.money << endl;
- cout << "Current " << itemName << " is: ";
- //show how many of chosen item the player has in backpack
- switch(menuChoice)
- {
- case 1:{cout << player.healthPacks << endl;}break;
- case 2:{cout << player.pistolAmmo << endl;}break;
- case 3:{cout << player.shotgunAmmo << endl;}break;
- case 4:{cout << player.rifleAmmo << endl;}break;
- default: cout << "Error" << endl;
- }
- cout << "\n";
- menuChoice = 0;
- amountChoice = 0;
- confirmPurchase = 0;
- save(player, dinosaur);
- shop(player, dinosaur);
- }
- if(confirmPurchase == 2)
- {
- cout << "Ok what else would you like?\n" << endl;
- menuChoice = 0;
- amountChoice = 0;
- confirmPurchase = 0;
- break;
- }
- }break;
- }
- }
- }//End of while loop
- }
- /*
- =================|
- Backpack function|
- =================|
- */
- void backpack(Player &player, Dinosaur &dinosaur)
- {
- cout << "ITEMS\n" << endl;
- cout << "money $" << player.money << endl;
- cout << "Health Packs: " << player.healthPacks << endl;
- cout << "Pistol Ammo: " << player.pistolAmmo << endl;
- cout << "Shotgun Ammo: " << player.shotgunAmmo << endl;
- cout << "Rifle Ammo: " << player.rifleAmmo << endl;
- cout << "\n";
- cout << "WEAPONS\n" << endl;
- cout << "Pistol - Does 3 points of damage against enemies" << endl;
- cout << "Shotgun - Does 9 points of damage against enemies" << endl;
- cout << "Rifle - Does 13 points of damage against enemies" << endl;
- }
- /*
- =====================|
- Player Stats function|
- =====================|
- */
- void stats(Player &player, Dinosaur &dinosaur)
- {
- cout << "STATS\n" << endl;
- }
- void gameInfo()
- {
- cout << "GAME INFO\n" << endl;
- cout << "Lines of Code: 931" << endl;
- }
- /*
- ==================|
- Main Game function|
- ==================|
- */
- void MainGame(Player &player, Dinosaur &dinosaur)
- {
- string strChoice;
- int intChoice;
- cout << "1) Start Battle" << endl;
- cout << "2) View Stats" << endl;
- cout << "3) General Store" << endl;
- cout << "4) View Backpack" << endl;
- cout << "5) Save Game" << endl;
- do
- {
- stringstream ss;
- getline(cin, strChoice);
- ss << strChoice;
- ss >> intChoice;
- if(intChoice == 1)
- {
- dinoSelect(player, dinosaur);
- }
- else if(intChoice == 2)
- {
- stats(player, dinosaur);
- }
- else if(intChoice == 3)
- {
- shop(player, dinosaur);
- }
- else if(intChoice == 4)
- {
- backpack(player, dinosaur);
- }
- else if(intChoice == 5)
- {
- save(player, dinosaur);
- }
- }
- while(intChoice != -1);
- }
- /*
- ========================|
- Dinosaur select function|
- ========================|
- */
- void dinoSelect(Player &player, Dinosaur &dinosaur)
- {
- switch(dinosaur.createTime)
- {
- case 0:
- {
- cout << "Your opponent is the T-Rex!!\n" << endl;
- while(player.playerHealth >= 1);
- {
- arena(player, dinosaur);
- trex(player, dinosaur);
- }
- }break;
- }
- }
- /*
- ==============|
- Arena function|
- ==============|
- */
- void arena(Player &player, Dinosaur &dinosaur)
- {
- int choice;
- int miss;
- int useHealth;
- time_t T;
- time(&T);
- srand(T);
- for(int i = 0; i < 5; i++)
- {
- miss = rand() % 5;
- }
- flags(player, dinosaur);
- cout << "==========================" << endl;
- cout << "----------TURN " << player.turns << "----------"<< endl;
- cout << "==========================\n" << endl;
- player.turns++;
- cout << "Make your move\n" << endl;
- cout << "Your health " << player.playerHealth << endl;
- cout << "Dinosaur health " << dinosaur.dinosaurHealth << endl;
- cout << "\n";
- cout << "ITEMS\n";
- cout << "Pistol Ammo " << player.pistolAmmo << endl;
- cout << "Shotgun Ammo " << player.shotgunAmmo << endl;
- cout << "Rifle Ammo " << player.rifleAmmo << endl;
- cout << "\n";
- cout << "What do you want to use?" << endl;
- cout << "1) Pistol" << endl;
- cout << "\t Damage: 3" << endl;
- cout << "\t\t Ammo used: 17 rounds" << endl;
- cout << "2) Shotgun" << endl;
- cout << "\t Damage: 9" << endl;
- cout << "\t\t Ammo used: 8 rounds" << endl;
- cout << "3) Rifle" << endl;
- cout << "\t Damage: 13" << endl;
- cout << "\t\t Ammo used: 32 rounds" << endl;
- cout << "4) Use Health Pack - +50 health" << endl;
- cin >> choice;
- cout << "\n";
- switch(choice)
- {
- case 1://Pistol Choice
- {
- if(miss == 0)
- {
- cout << "Your attack missed!!\n" << endl;
- dinosaur.dinosaurHealth -= 0;
- player.pistolAmmo -= 0;
- }
- if(miss == 4)
- {
- cout << "Double Damage Bonus!!\n" << endl;
- if(player.pistolAmmo >= 17)
- {
- cout << "Enough ammo" << endl;
- player.pistolAmmo -= 17;
- dinosaur.dinosaurHealth -= 6;
- }
- if((player.pistolAmmo < 17) && (player.pistolAmmo >= 1))
- {
- cout << "But you dont have enough Ammo, you only did regular damage!" << endl;
- cout << "Used " << player.pistolAmmo << " Pistol rounds" << endl;
- player.pistolAmmo -= player.pistolAmmo;
- dinosaur.dinosaurHealth -= 3;
- }
- if(player.pistolAmmo == 0)
- {
- cout << "No ammo left for the Pistol!!" << endl;
- player.pistolAmmo -= 0;
- dinosaur.dinosaurHealth -= 0;
- }
- else if((miss != 0) &&(miss != 4))//If none of the above applies then execute this else statement
- {
- cout << "You hit the enemy\n" << endl;
- if(player.pistolAmmo >= 17)
- {
- cout << "Enough ammo" << endl;
- player.pistolAmmo -= 17;
- dinosaur.dinosaurHealth -= 3;
- }
- if((player.pistolAmmo < 17) && (player.pistolAmmo >= 1))
- {
- cout << "Not enough Ammo" << endl;
- cout << "Used " << player.pistolAmmo << " Pistol rounds" << endl;
- player.pistolAmmo -= player.pistolAmmo;
- dinosaur.dinosaurHealth -= 2;
- }
- if(player.pistolAmmo == 0)
- {
- cout << "No ammo left for the Pistol!!" << endl;
- player.pistolAmmo -= 0;
- dinosaur.dinosaurHealth -= 0;
- }
- }//End of else statement
- }//end of else if
- }break;//End of Case 1
- case 2://Shotgun Choice
- {
- if(miss == 0)
- {
- cout << "Your attack missed!!\n" << endl;
- dinosaur.dinosaurHealth -= 0;
- player.shotgunAmmo -= 0;
- }
- if(miss == 4)
- {
- cout << "Double Damage Bonus!!\n" << endl;
- if(player.shotgunAmmo >= 9)
- {
- cout << "Enough ammo" << endl;
- player.shotgunAmmo -= 17;
- dinosaur.dinosaurHealth -= 6;
- }
- if((player.shotgunAmmo < 9) && (player.shotgunAmmo >= 1))
- {
- cout << "But you dont have enough Ammo, you only did regular damage!" << endl;
- cout << "Used " << player.shotgunAmmo << " Shotgun rounds" << endl;
- player.shotgunAmmo -= player.shotgunAmmo;
- dinosaur.dinosaurHealth -= 3;
- }
- if(player.shotgunAmmo == 0)
- {
- cout << "No ammo left for the Shotgun!!" << endl;
- player.shotgunAmmo -= 0;
- dinosaur.dinosaurHealth -= 0;
- }
- else if((miss != 0) &&(miss != 4))//If none of the above applies then execute this else statement
- {
- cout << "You hit the enemy\n" << endl;
- if(player.shotgunAmmo >= 9)
- {
- cout << "Enough ammo" << endl;
- player.shotgunAmmo -= 17;
- dinosaur.dinosaurHealth -= 3;
- }
- if((player.shotgunAmmo < 9) && (player.shotgunAmmo >= 1))
- {
- cout << "Not enough Ammo" << endl;
- cout << "You used " << player.shotgunAmmo << " Shotgun rounds" << endl;
- player.shotgunAmmo -= player.shotgunAmmo;
- dinosaur.dinosaurHealth -= 2;
- }
- if(player.shotgunAmmo == 0)
- {
- cout << "No ammo left for the Shotgun!!" << endl;
- player.shotgunAmmo -= 0;
- dinosaur.dinosaurHealth -= 0;
- }
- }//End of else statement
- }//end of else if
- }break;//End of Case 2
- case 3://Rifle Choice
- {
- if(miss == 0)
- {
- cout << "Your attack missed!!\n" << endl;
- dinosaur.dinosaurHealth -= 0;
- player.rifleAmmo -= 0;
- }
- if(miss == 4)
- {
- cout << "Double Damage Bonus!!\n" << endl;
- if(player.rifleAmmo >= 17)
- {
- cout << "Enough ammo" << endl;
- player.rifleAmmo -= 17;
- dinosaur.dinosaurHealth -= 6;
- }
- if((player.rifleAmmo < 17) && (player.rifleAmmo >= 1))
- {
- cout << "But you dont have enough Ammo, you only did regular damage!" << endl;
- cout << "Used " << player.rifleAmmo << " Rifle rounds" << endl;
- player.rifleAmmo -= player.rifleAmmo;
- dinosaur.dinosaurHealth -= 3;
- }
- if(player.rifleAmmo == 0)
- {
- cout << "No ammo left for the Rifle!!" << endl;
- player.rifleAmmo -= 0;
- dinosaur.dinosaurHealth -= 0;
- }
- else if((miss != 0) &&(miss != 4))//If none of the above applies then execute this else statement
- {
- cout << "You hit the enemy\n" << endl;
- if(player.rifleAmmo >= 17)
- {
- cout << "Enough ammo" << endl;
- player.rifleAmmo -= 17;
- dinosaur.dinosaurHealth -= 3;
- }
- if((player.rifleAmmo < 17) && (player.rifleAmmo >= 1))
- {
- cout << "Not enough Ammo" << endl;
- cout << "Used " << player.rifleAmmo << " Rifle rounds" << endl;
- player.rifleAmmo -= player.rifleAmmo;
- dinosaur.dinosaurHealth -= 2;
- }
- if(player.rifleAmmo == 0)
- {
- cout << "No ammo left for the Rifle!!" << endl;
- player.rifleAmmo -= 0;
- dinosaur.dinosaurHealth -= 0;
- }
- }//End of else statement
- }//end of else if
- }break;
- case 4://Health pack choice
- {
- cout << "Use health pack?" << endl;
- cout << "1) Use" << endl;
- cout << "2) Don't Use" << endl;
- cin >> useHealth;
- if(useHealth == 1)
- {
- cout << "\n";
- cout << "Health pack used +50 health restored\n" << endl;
- player.playerHealth += 50;
- player.healthPacks -= 1;
- }
- if(useHealth == 2)
- {
- cout << "Did not use a health pack" << endl;
- }
- }break;
- }
- }
- /*
- ==============|
- T-Rex function|
- ==============|
- */
- void trex(Player &player, Dinosaur &dinosaur)
- {
- switch(dinosaur.createTime)
- {
- case 0:
- {
- cout << "T-Rex used Bite!!\n" << endl;
- player.playerHealth -= 5;
- }break;
- case 1:
- {
- cout << "T-Rex used Stomp!!\n" << endl;
- player.playerHealth -= 9;
- }break;
- case 2:
- {
- cout << "T-Rex used Crunch\n" << endl;
- player.playerHealth -= 13;
- }break;
- case 3:
- {
- cout << "T-Rex used Slam\n" << endl;
- player.playerHealth -= 19;
- }break;
- case 4:
- {
- cout << "T-Rex used Pulverize\n" << endl;
- player.playerHealth -= 23;
- }break;
- default:
- {
- cout << "T-Rex attack missed!!\n" << endl;
- player.playerHealth -= 0;
- }
- }
- }
- /*
- ==========================|
- Conditional flags function|
- ==========================|
- */
- void flags(Player &player, Dinosaur &dinosaur)
- {
- if(player.playerHealth <= 0)
- {
- cout << "\n";
- cout << "->You died game over<-\n" << endl;
- MainGame(player, dinosaur);
- }
- else if((player.playerHealth >= 1) && (dinosaur.dinosaurHealth <= 0))
- {
- player.money += 250;
- player.score++;
- cout << "\n";
- cout << "->You have won!!!<-\n" << endl;
- cout << "Score " << player.score << endl;
- cout << "player.money+ $" << player.money << endl;
- cout << "\n";
- MainGame(player, dinosaur);
- }
- }
- /*
- ====|
- Main|
- ====|
- */
- int main()
- {
- vector<int> tItems;
- tItems.push_back(5);
- time_t T;
- unsigned int Time;
- time(&T);
- srand(T);
- for(int i = 0; i < 5; i++)
- {
- Time = rand() % 5;
- }
- Player player(100,
- 0,
- 0,
- 0,
- 0,
- 500,
- 0,
- 0,
- tItems);
- Dinosaur dinosaur(100, 5, Time);
- Menu(player, dinosaur);
- //dinoSelect(player, dinosaur);
- }
- //Player.h
- #ifndef PLAYER_H
- #define PLAYER_H
- #include <vector>
- /*
- ============|
- Player Class|
- ============|
- */
- class Player
- {
- public:
- Player(unsigned int PLAYERHEALTH, unsigned int PISTOLAMMO,
- unsigned int SHOTGUNAMMO, unsigned int RIFLEAMMO,
- unsigned int SCORE, unsigned int MONEY,
- unsigned int HEALTHPACKS, int TURNS, std::vector<int> ITEMS);
- private:
- unsigned int playerHealth;
- unsigned int pistolAmmo;
- unsigned int shotgunAmmo;
- unsigned int rifleAmmo;
- unsigned int score;
- unsigned int money;
- unsigned int healthPacks;
- unsigned int turns;
- std::vector<int> items;
- };
- #endif // PLAYER_H
- //Prototypes.h
- #ifndef PROTOTYPES_H_INCLUDED
- #define PROTOTYPES_H_INCLUDED
- #include <string>
- void save(Player &player, Dinosaur &dinosaur);
- void load(Player &player, Dinosaur &dinosaur);
- void shop(Player &player, Dinosaur &dinosaur);
- void arena(Player &player, Dinosaur &dinosaur);
- void backpack(Player &player, Dinosaur &dinosaur);
- void flags(Player &player, Dinosaur &dinosaur);
- void dinoSelect(Player &player, Dinosaur &dinosaur);
- void stats(Player &player, Dinosaur &dinosaur);
- void trex(Player &player, Dinosaur &dinosaur);
- void velociraptor(Player &player, Dinosaur &dinosaur);
- int Menu(Player &player, Dinosaur &dinosaur);
- void MainGame(Player &player, Dinosaur &dinosaur);
- int IntegerProcessing(Player &player, Dinosaur &dinosaur, int, int, std::string, std::string);
- std::string StringProcessing(Player &player, Dinosaur &dinosaur);
- void gameInfo();
- #endif // PROTOTYPES_H_INCLUDED
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement