Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [Code=cpp]
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <vector>
- #include <cstdlib>
- #include <ctime>
- #include "player.h"
- #include "Dinosaur.h"
- int main()
- {
- int choice;
- player pc;
- std::cout << "Build 1.2.0" << std::endl;
- std::cout << "\n";
- std::cout << "DINOSAUR ARENA\n" << std::endl;
- std::cout << "What do you want to do?\n" << std::endl;
- std::cout << "1) Load Game" << std::endl;
- std::cout << "2) New Game" << std::endl;
- std::cout << "3) Quit Game" << std::endl;
- std::cin >> choice;
- if(choice == 1)
- {
- pc.load();
- }
- else if(choice == 2)
- {
- pc.MainGame();
- }
- else if(choice == 3)
- {
- return 0;
- }
- }
- /*
- =============|
- Save function|
- =============|
- */
- void player::save()
- {
- std::ofstream fileOut;
- fileOut.open("DASave.txt");
- fileOut << get_playerHealth() << std::endl;
- fileOut << get_pistolAmmo() << std::endl;
- fileOut << get_shotgunAmmo() << std::endl;
- fileOut << get_rifleAmmo() << std::endl;
- fileOut << get_score() << std::endl;
- fileOut << get_money() << std::endl;
- fileOut << get_healthPacks() << std::endl;
- MainGame();
- }
- /*
- =============|
- Load function|
- =============|
- */
- void player::load()
- {
- std::ifstream fileIn;
- fileIn.open("DASave.txt");
- fileIn >> playerHealth;
- fileIn >> pistolAmmo;
- fileIn >> shotgunAmmo;
- fileIn >> rifleAmmo;
- fileIn >> score;
- fileIn >> money;
- fileIn >> healthPacks;
- std::cout << "Health: " << playerHealth << std::endl;
- std::cout << "Pistol Ammo: " << pistolAmmo << std::endl;
- std::cout << "Shotgun Ammo: " << shotgunAmmo << std::endl;
- std::cout << "Rifle Ammo: " << rifleAmmo << std::endl;
- std::cout << "Score: " << score << std::endl;
- std::cout << "Money: " << money << std::endl;
- std::cout << "Health Packs: " << healthPacks << std::endl;
- std::cout << "\n";
- MainGame();
- }
- /*
- =============|
- Shop function|
- =============|
- */
- void player::shop()
- {
- int menuChoice;
- int amountChoice = 0;
- std::string inv;
- items[0] = 0;
- items[1] = 0;
- items[2] = 0;
- items[3] = 0;
- std::cout << "\n";
- std::cout << "GENERAL STORE\n" << std::endl;
- std::cout << "Type in -1 to quit" << std::endl;
- std::cout << "1) Health Pack - $5" << std::endl;
- std::cout << "2) Pistol Ammo - $2" << std::endl;
- std::cout << "3) Shotgun Ammo - $5" << std::endl;
- std::cout << "4) Rifle Ammo - $18" << std::endl;
- std::cin >> menuChoice;
- while((amountChoice != -1) || (menuChoice != -1))
- {
- if((amountChoice == -1) || (menuChoice == -1))
- {
- std::cout << "Thank you for shopping at the store\n" << std::endl;
- MainGame();
- break;
- }
- else
- {
- switch(menuChoice)
- {
- case 1:
- {
- std::cout << "How many Health Packs do you want to buy?" << std::endl;
- std::cout << "$5 per health pack" << std::endl;
- while(amountChoice != -1)
- {
- std::cin >> amountChoice;
- items[0] = amountChoice;
- if(money >= items[0] * 5)
- {
- money -= items[0] * 5;
- healthPacks += amountChoice;
- std::cout << "Current money equals $" << money << std::endl;
- std::cout << "Current Health Packs: " << healthPacks << std::endl;
- std::cout << "\n";
- amountChoice = 0;
- save();
- shop();
- }
- else
- {
- std::cout << "You do not have enough money" << std::endl;
- }
- }
- }break;
- case 2:
- {
- std::cout << "How much Pistol Ammo do you want to buy?" << std::endl;
- std::cin >> amountChoice;
- items[1] = amountChoice;
- if(money >= items[1] * 2)
- {
- money -= items[1] * 2;
- pistolAmmo += amountChoice;
- std::cout << "Current money equals $" << money << std::endl;
- std::cout << "Current Pistol Ammo: " << pistolAmmo << std::endl;
- std::cout << "\n";
- amountChoice = 0;
- save();
- shop();
- }
- else
- {
- std::cout << "You do not have enough money" << std::endl;
- }
- }break;
- case 3:
- {
- std::cout << "How much Shotgun Ammo do you want to buy?" << std::endl;
- std::cin >> amountChoice;
- items[2] = amountChoice;
- if(money >= items[2] * 5)
- {
- money -= items[2] * 5;
- shotgunAmmo += amountChoice;
- std::cout << "Current money equals $" << money << std::endl;
- std::cout << "Current Shotgun Ammo: " << shotgunAmmo << std::endl;
- std::cout << "\n";
- amountChoice = 0;
- save();
- shop();
- }
- else
- {
- std::cout << "You do not have enough money" << std::endl;
- }
- }break;
- case 4:
- {
- std::cout << "How much Rifle Ammo do you want to buy?" << std::endl;
- std::cin >> amountChoice;
- items[3] = amountChoice;
- if(money >= items[3] * 18)
- {
- money -= items[3] * 18;
- rifleAmmo += amountChoice;
- std::cout << "Current money equals $" << money << std::endl;
- std::cout << "Current Rifle Ammo: " << rifleAmmo << std::endl;
- std::cout << "\n";
- amountChoice = 0;
- save();
- shop();
- }
- else
- {
- std::cout << "You do not have enough money" << std::endl;
- }
- }break;
- }//End of switch statement
- }
- }//End of while loop
- }
- /*
- =================|
- Backpack function|
- =================|
- */
- void player::backpack()
- {
- std::cout << "ITEMS\n" << std::endl;
- std::cout << "Money $" << money << std::endl;
- std::cout << "Health Packs: " << healthPacks << std::endl;
- std::cout << "Pistol Ammo: " << pistolAmmo << std::endl;
- std::cout << "Shotgun Ammo: " << shotgunAmmo << std::endl;
- std::cout << "Rifle Ammo: " << rifleAmmo << std::endl;
- std::cout << "\n";
- std::cout << "WEAPONS\n" << std::endl;
- std::cout << "Pistol - Does 3 points of damage against enemies" << std::endl;
- std::cout << "Shotgun - Does 9 points of damage against enemies" << std::endl;
- std::cout << "Rifle - Does 13 points of damage against enemies" << std::endl;
- }
- void player::stats()
- {
- std::cout << "STATS\n" << std::endl;
- }
- /*
- ==================|
- Main Game function|
- ==================|
- */
- void player::MainGame()
- {
- int choice;
- std::cout << "1) Start Battle" << std::endl;
- std::cout << "2) View Stats" << std::endl;
- std::cout << "3) General Store" << std::endl;
- std::cout << "4) View Backpack" << std::endl;
- std::cout << "5) Save Game" << std::endl;
- std::cin >> choice;
- if(choice == 1)
- {
- dinoSelect();
- }
- else if(choice == 2)
- {
- stats();
- }
- else if(choice == 3)
- {
- shop();
- }
- else if(choice == 4)
- {
- backpack();
- }
- else if(choice == 5)
- {
- save();
- }
- }
- /*
- ========================|
- Dinosaur select function|
- ========================|
- */
- void player::dinoSelect()
- {
- time_t T;
- time(&T);
- srand(T);
- int Time;
- dinosaur D;
- Time = rand() % 2;
- switch(Time)
- {
- case 0:
- {
- std::cout << "Your opponent is the T-Rex!!\n" << std::endl;
- do
- {
- D.arena();
- D.trex();
- }
- while(playerHealth >= 1);
- }break;
- case 1:
- {
- std::cout << "Your opponent is the Raptor!!\n" << std::endl;
- do
- {
- D.arena();
- D.velociraptor();
- }
- while(playerHealth >= 1);
- }break;
- }
- }
- /*
- ==============|
- Arena function|
- ==============|
- */
- void dinosaur::arena()
- {
- int choice;
- int miss;
- int useHealth;
- time_t T;
- time(&T);
- srand(T);
- for(int i = 0; i < 5; i++)
- {
- miss = rand() % 5;
- }
- flags();
- std::cout << "==========================" << std::endl;
- std::cout << "----------TURN " << turns << "----------"<< std::endl;
- std::cout << "==========================\n" << std::endl;
- turns++;
- std::cout << "Make your move\n" << std::endl;
- std::cout << "Your health " << get_playerHealth() << std::endl;
- std::cout << "Dinosaur health " << get_dinosaurHealth() << std::endl;
- std::cout << "\n";
- std::cout << "ITEMS\n";
- std::cout << "Pistol Ammo " << get_pistolAmmo() << std::endl;
- std::cout << "Shotgun Ammo " << get_shotgunAmmo() << std::endl;
- std::cout << "Rifle Ammo " << get_rifleAmmo() << std::endl;
- std::cout << "\n";
- std::cout << "What do you want to use?" << std::endl;
- std::cout << "1) Pistol" << std::endl;
- std::cout << "\t Damage: 3" << std::endl;
- std::cout << "\t\t Ammo used: 17 rounds" << std::endl;
- std::cout << "2) Shotgun" << std::endl;
- std::cout << "\t Damage: 9" << std::endl;
- std::cout << "\t\t Ammo used: 8 rounds" << std::endl;
- std::cout << "3) Rifle" << std::endl;
- std::cout << "\t Damage: 13" << std::endl;
- std::cout << "\t\t Ammo used: 32 rounds" << std::endl;
- std::cout << "4) Use Health Pack - +50 health" << std::endl;
- std::cin >> choice;
- std::cout << "\n";
- switch(choice)
- {
- case 1://Pistol Choice
- {
- if(miss = 0)
- {
- std::cout << "Your attack missed!!\n" << std::endl;
- dinosaurHealth -= 0;
- pistolAmmo -= 0;
- }
- if(miss = 4)
- {
- std::cout << "Double Damage Bonus!!\n" << std::endl;
- if(pistolAmmo >= 17)
- {
- std::cout << "Enough ammo" << std::endl;
- pistolAmmo -= 17;
- dinosaurHealth -= 6;
- }
- if((pistolAmmo < 17) && (pistolAmmo >= 1))
- {
- std::cout << "But you dont have enough Ammo, you only did regular damage!" << std::endl;
- std::cout << "Used " << pistolAmmo << " Pistol rounds" << std::endl;
- pistolAmmo -= pistolAmmo;
- dinosaurHealth -= 3;
- }
- if(pistolAmmo = 0)
- {
- std::cout << "No ammo left for the Pistol!!" << std::endl;
- pistolAmmo -= 0;
- dinosaurHealth -= 0;
- }
- else if((miss != 0) &&(miss != 4))//If none of the above applies then execute this else statement
- {
- std::cout << "You hit the enemy\n" << std::endl;
- if(pistolAmmo >= 17)
- {
- std::cout << "Enough ammo" << std::endl;
- pistolAmmo -= 17;
- dinosaurHealth -= 3;
- }
- if((pistolAmmo < 17) && (pistolAmmo >= 1))
- {
- std::cout << "Not enough Ammo" << std::endl;
- std::cout << "Used " << pistolAmmo << " Pistol rounds" << std::endl;
- pistolAmmo -= pistolAmmo;
- dinosaurHealth -= 2;
- }
- if(pistolAmmo = 0)
- {
- std::cout << "No ammo left for the Pistol!!" << std::endl;
- pistolAmmo -= 0;
- dinosaurHealth -= 0;
- }
- }//End of else statement
- }//end of else if
- }break;//End of Case 1
- case 2://Shotgun Choice
- {
- if(miss = 0)
- {
- std::cout << "Your attack missed!!\n" << std::endl;
- dinosaurHealth -= 0;
- shotgunAmmo -= 0;
- }
- if(miss = 4)
- {
- std::cout << "Double Damage Bonus!!\n" << std::endl;
- if(shotgunAmmo >= 9)
- {
- std::cout << "Enough ammo" << std::endl;
- shotgunAmmo -= 8;
- dinosaurHealth -= 6;
- }
- if((shotgunAmmo < 9) && (shotgunAmmo >= 1))
- {
- std::cout << "But you dont have enough Ammo, you only did regular damage!" << std::endl;
- std::cout << "Used " << shotgunAmmo << " Shotgun rounds" << std::endl;
- shotgunAmmo -= shotgunAmmo;
- dinosaurHealth -= 3;
- }
- if(shotgunAmmo = 0)
- {
- std::cout << "No ammo left for the Shotgun!!" << std::endl;
- shotgunAmmo -= 0;
- dinosaurHealth -= 0;
- }
- else if((miss != 0) &&(miss != 4))//If none of the above applies then execute this else statement
- {
- std::cout << "You hit the enemy\n" << std::endl;
- if(shotgunAmmo >= 9)
- {
- std::cout << "Enough ammo" << std::endl;
- shotgunAmmo -= 8;
- dinosaurHealth -= 3;
- }
- if((shotgunAmmo < 9) && (shotgunAmmo >= 1))
- {
- std::cout << "Not enough Ammo" << std::endl;
- std::cout << "You used " << shotgunAmmo << " Shotgun rounds" << std::endl;
- shotgunAmmo -= shotgunAmmo;
- dinosaurHealth -= 2;
- }
- if(shotgunAmmo == 0)
- {
- std::cout << "No ammo left for the Shotgun!!" << std::endl;
- shotgunAmmo -= 0;
- dinosaurHealth -= 0;
- }
- }//End of else statement
- }//end of else if
- }break;//End of Case 2
- case 3://Rifle Choice
- {
- if(miss = 0)
- {
- std::cout << "Your attack missed!!\n" << std::endl;
- dinosaurHealth -= 0;
- rifleAmmo -= 0;
- }
- if(miss = 4)
- {
- std::cout << "Double Damage Bonus!!\n" << std::endl;
- if(rifleAmmo >= 17)
- {
- std::cout << "Enough ammo" << std::endl;
- rifleAmmo -= 17;
- dinosaurHealth -= 6;
- }
- if((rifleAmmo < 17) && (rifleAmmo >= 1))
- {
- std::cout << "But you dont have enough Ammo, you only did regular damage!" << std::endl;
- std::cout << "Used " << rifleAmmo << " Rifle rounds" << std::endl;
- rifleAmmo -= rifleAmmo;
- dinosaurHealth -= 3;
- }
- if(rifleAmmo = 0)
- {
- std::cout << "No ammo left for the Rifle!!" << std::endl;
- rifleAmmo -= 0;
- dinosaurHealth -= 0;
- }
- else if((miss != 0) &&(miss != 4))//If none of the above applies then execute this else statement
- {
- std::cout << "You hit the enemy\n" << std::endl;
- if(rifleAmmo >= 17)
- {
- std::cout << "Enough ammo" << std::endl;
- rifleAmmo -= 17;
- dinosaurHealth -= 3;
- }
- if((rifleAmmo < 17) && (rifleAmmo >= 1))
- {
- std::cout << "Not enough Ammo" << std::endl;
- std::cout << "Used " << rifleAmmo << " Rifle rounds" << std::endl;
- rifleAmmo -= rifleAmmo;
- dinosaurHealth -= 2;
- }
- if(rifleAmmo = 0)
- {
- std::cout << "No ammo left for the Rifle!!" << std::endl;
- rifleAmmo -= 0;
- dinosaurHealth -= 0;
- }
- }//End of else statement
- }//end of else if
- }break;
- case 4://Health pack choice
- {
- std::cout << "Use health pack?" << std::endl;
- std::cout << "1) Use" << std::endl;
- std::cout << "2) Don't Use" << std::endl;
- std::cin >> useHealth;
- if(useHealth == 1)
- {
- std::cout << "\n";
- std::cout << "Health pack used +50 health restored\n" << std::endl;
- playerHealth += 50;
- healthPacks -= 1;
- }
- if(useHealth == 2)
- {
- std::cout << "Did not use a health pack" << std::endl;
- }
- }break;
- }
- }
- /*
- ==============|
- T-Rex function|
- ==============|
- */
- void dinosaur::trex()
- {
- int TrexHealth = 0;
- time_t T;
- time(&T);
- srand(T);
- int Time;
- Time = rand() % 6;
- TrexHealth = dinosaurHealth;
- flags();
- switch(Time)
- {
- case 0:
- {
- std::cout << "T-Rex used Bite!!\n" << std::endl;
- playerHealth -= 5;
- }break;
- case 1:
- {
- std::cout << "T-Rex used Stomp!!\n" << std::endl;
- playerHealth -= 9;
- }break;
- case 2:
- {
- std::cout << "T-Rex used Crunch\n" << std::endl;
- playerHealth -= 13;
- }break;
- case 3:
- {
- std::cout << "T-Rex used Slam\n" << std::endl;
- playerHealth -= 19;
- }break;
- case 4:
- {
- std::cout << "T-Rex used Pulverize\n" << std::endl;
- playerHealth -= 23;
- }break;
- default:
- {
- std::cout << "T-Rex attack missed!!\n" << std::endl;
- playerHealth -= 0;
- }
- }
- }
- /*
- ===============|
- Raptor function|
- ===============|
- */
- void dinosaur::velociraptor()
- {
- int RaptorHealth = 0;
- time_t T;
- time(&T);
- srand(T);
- int Time;
- Time = rand() % 6;
- RaptorHealth = dinosaurHealth;
- flags();
- switch(Time)
- {
- case 0:
- {
- std::cout << "Raptor used Bite!!\n" << std::endl;
- playerHealth -= 5;
- }break;
- case 1:
- {
- std::cout << "Raptor used Slash!!\n" << std::endl;
- playerHealth -= 9;
- }break;
- case 2:
- {
- std::cout << "Raptor used Leap Attack\n" << std::endl;
- playerHealth -= 13;
- }break;
- case 3:
- {
- std::cout << "Raptor used Slam\n" << std::endl;
- playerHealth -= 19;
- }break;
- case 4:
- {
- std::cout << "Raptor used Shred\n" << std::endl;
- playerHealth -= 23;
- }break;
- default:
- {
- std::cout << "Raptors attack missed!!\n" << std::endl;
- playerHealth -= 0;
- }
- }
- }
- /*
- ==========================|
- Conditional flags function|
- ==========================|
- */
- void dinosaur::flags()
- {
- if(playerHealth <= 0)
- {
- std::cout << "\n";
- std::cout << "->You died game over<-\n" << std::endl;
- turns == 0;
- MainGame();
- }
- if((playerHealth >= 1) && (dinosaurHealth <= 0))
- {
- money += 250;
- score++;
- std::cout << "\n";
- std::cout << "->You have won!!!<-\n" << std::endl;
- std::cout << "Score " << score << std::endl;
- std::cout << "Money+ $" << money << std::endl;
- std::cout << "\n";
- turns == 0;
- MainGame();
- }
- }
- [/Code]
- player.h
- #ifndef PLAYER_H
- #define PLAYER_H
- #include <vector>
- #include <string>
- /*
- ============|
- Player Class|
- ============|
- */
- class player
- {
- protected:
- int playerHealth;
- int pistolAmmo;
- int shotgunAmmo;
- int rifleAmmo;
- int score;
- int money;
- int healthPacks;
- int turns;
- int *items;
- public:
- void save();
- void load();
- void MainGame();
- void shop();
- void backpack();
- void stats();
- void dinoSelect();
- player();
- ~player();
- void set_health(int H);
- void set_pistolAmmo(int PA);
- void set_shotgunAmmo(int SA);
- void set_rifleAmmo(int RA);
- void set_score(int S);
- void set_money(int M);
- void set_items(int *I);
- void set_healthPacks(int HP);
- void set_turns(int T);
- int get_playerHealth();
- int get_pistolAmmo();
- int get_shotgunAmmo();
- int get_rifleAmmo();
- int get_score();
- int get_money();
- int *get_items();
- int get_healthPacks();
- int get_turns();
- };
- player::player(): playerHealth(100), pistolAmmo(9), shotgunAmmo(15),
- rifleAmmo(25), score(0), money(100), healthPacks(1),
- items(new int[4]), turns(1)
- {
- for(int i = 0; i < 4; ++i)
- {
- items[i] = 0;
- }
- }
- player::~player()
- {
- if(items)
- {
- delete[] items;
- }
- }
- void player::set_health(int H)
- {
- playerHealth = H;
- }
- void player::set_pistolAmmo(int PA)
- {
- pistolAmmo = PA;
- }
- void player::set_shotgunAmmo(int SA)
- {
- shotgunAmmo = SA;
- }
- void player::set_rifleAmmo(int RA)
- {
- rifleAmmo = RA;
- }
- void player::set_score(int S)
- {
- score = S;
- }
- void player::set_money(int M)
- {
- money = M;
- }
- void player::set_items(int *I)
- {
- items = I;
- }
- void player::set_healthPacks(int HP)
- {
- healthPacks = HP;
- }
- void player::set_turns(int T)
- {
- turns = T;
- }
- int player::get_playerHealth()
- {
- return playerHealth;
- }
- int player::get_pistolAmmo()
- {
- return pistolAmmo;
- }
- int player::get_shotgunAmmo()
- {
- return shotgunAmmo;
- }
- int player::get_rifleAmmo()
- {
- return rifleAmmo;
- }
- int player::get_score()
- {
- return score;
- }
- int player::get_money()
- {
- return money;
- }
- int *player::get_items()
- {
- return items;
- }
- int player::get_healthPacks()
- {
- return healthPacks;
- }
- int player::get_turns()
- {
- return turns;
- }
- #endif // PLAYER_H
- dinosaur.h
- #ifndef DINOSAUR_H_INCLUDED
- #define DINOSAUR_H_INCLUDED
- #include "player.h"
- /*
- ==============|
- Dinosaur Class|
- ==============|
- */
- class dinosaur : public player
- {
- protected:
- int dinosaurHealth;
- int *attacks;
- public:
- void trex();
- void velociraptor();
- void flags();
- void arena();
- dinosaur();
- ~dinosaur();
- void set_dinosaurHealth(int DH);
- void set_attacks(int *A);
- int get_dinosaurHealth();
- int *get_attacks();
- };
- dinosaur::dinosaur(): dinosaurHealth(100), attacks(new int[0])
- {
- }
- dinosaur::~dinosaur()
- {
- if(attacks)
- delete[] attacks;
- }
- void dinosaur::set_dinosaurHealth(int DH)
- {
- dinosaurHealth = DH;
- }
- void dinosaur::set_attacks(int *A)
- {
- if(attacks)
- delete[] attacks;
- attacks = A;
- }
- //--------------------------------------------
- int dinosaur::get_dinosaurHealth()
- {
- return dinosaurHealth;
- }
- int *dinosaur::get_attacks()
- {
- return attacks;
- }
- #endif // DINOSAUR_H_INCLUDED
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement