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"
- void save();
- void load();
- void shop();
- void arena();
- void backpack();
- void flags();
- void dinoSelect();
- void stats();
- void trex();
- void velociraptor();
- int main()
- {
- int choice;
- player pc;
- std::cout << "Build 1.0.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()
- {
- }
- /*
- ==================|
- 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
- {
- switch(miss)
- {
- case 0:
- {
- std::cout << "Your attack missed!!\n" << std::endl;
- dinosaurHealth -= 0;
- pistolAmmo -= 0;
- }break;
- case 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;
- }
- else if(pistolAmmo == 0)
- {
- std::cout << "No ammo left for the Pistol!!" << std::endl;
- pistolAmmo -= 0;
- dinosaurHealth -= 0;
- }
- }break;
- default:
- {
- 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;
- }
- else if(pistolAmmo == 0)
- {
- std::cout << "No ammo left for the Pistol!!" << std::endl;
- pistolAmmo -= 0;
- dinosaurHealth -= 0;
- }
- }
- }//Miss Switch one
- }break;
- case 2://Shotgun Choice
- {
- switch(miss)
- {
- case 0:
- {
- std::cout << "Your attack missed!!\n" << std::endl;
- dinosaurHealth -= 0;
- shotgunAmmo -= 0;
- }break;
- case 4:
- {
- std::cout << "Double Damage Bonus!!\n" << std::endl;
- if(shotgunAmmo >= 8)
- {
- std::cout << "Enough ammo" << std::endl;
- shotgunAmmo -= 8;
- dinosaurHealth -= 16;
- }
- if((shotgunAmmo < 8) && (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 -= 8;
- }
- else if(shotgunAmmo == 0)
- {
- std::cout << "No ammo left for the Shotgun!!" << std::endl;
- shotgunAmmo -= 0;
- dinosaurHealth -= 0;
- }
- }break;
- default:
- {
- std::cout << "You hit the enemy\n" << std::endl;
- if(shotgunAmmo >= 17)
- {
- std::cout << "Enough ammo" << std::endl;
- shotgunAmmo -= 17;
- dinosaurHealth -= 3;
- }
- if((shotgunAmmo < 8) && (shotgunAmmo >= 1))
- {
- std::cout << "Not enough Ammo" << std::endl;
- std::cout << "Used " << shotgunAmmo << " Shotgun rounds" << std::endl;
- shotgunAmmo -= shotgunAmmo;
- dinosaurHealth -= 3;
- }
- else if(shotgunAmmo == 0)
- {
- std::cout << "No ammo left for the Shotgun!!" << std::endl;
- shotgunAmmo -= 0;
- dinosaurHealth -= 0;
- }
- }
- }//Miss Switch one
- }break;
- case 3://Rifle Choice
- {
- switch(miss)
- {
- case 0:
- {
- std::cout << "Your attack missed!!\n" << std::endl;
- dinosaurHealth -= 0;
- rifleAmmo -= 0;
- }break;
- case 4:
- {
- std::cout << "Double Damage Bonus!!\n" << std::endl;
- if(rifleAmmo >= 32)
- {
- std::cout << "Enough ammo" << std::endl;
- rifleAmmo -= 32;
- dinosaurHealth -= 26;
- }
- if((rifleAmmo < 32) && (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 -= 13;
- }
- else if(rifleAmmo == 0)
- {
- std::cout << "No ammo left for the Rifle!!" << std::endl;
- rifleAmmo -= 0;
- dinosaurHealth -= 0;
- }
- }break;
- default:
- {
- std::cout << "You hit the enemy\n" << std::endl;
- if(rifleAmmo >= 32)
- {
- std::cout << "Enough ammo" << std::endl;
- rifleAmmo -= 32;
- dinosaurHealth -= 13;
- }
- if((rifleAmmo < 32) && (rifleAmmo >= 1))
- {
- std::cout << "Not enough Ammo" << std::endl;
- std::cout << "Used " << rifleAmmo << " Rifle rounds" << std::endl;
- rifleAmmo -= rifleAmmo;
- dinosaurHealth -= 8;
- }
- else if(rifleAmmo == 0)
- {
- std::cout << "No ammo left for the Rifle!!" << std::endl;
- rifleAmmo -= 0;
- dinosaurHealth -= 0;
- }
- }
- }//Miss Switch one
- }break;
- case 4://Choice case
- {
- std::cout << "Use health pack?" << std::endl;
- std::cout << "1) Use" << std::endl;
- std::cin >> useHealth;
- std::cout << "\n";
- std::cout << "Health pack used +15 health reshopd\n" << std::endl;
- playerHealth += 50;
- healthPacks -= 1;
- }
- }
- }
- /*
- ==============|
- T-Rex function|
- ==============|
- */
- void dinosaur::trex()
- {
- int TrexHealth = 0;
- //int attacks[5] = {5,9,13,19,23};
- 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;
- //int attacks[5] = {5,9,13,19,23};
- 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))
- {
- std::cout << "\n";
- std::cout << "->You have won!!!<-\n" << std::endl;
- score++;
- std::cout << "Score " << score << std::endl;
- std::cout << "\n";
- turns == 0;
- money += 250;
- MainGame();
- }
- }
- [/Code]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement