Guest User

CstormGameCodeForCPlusPlusForums

a guest
Jan 14th, 2011
786
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 18.14 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <windows.h>
  6. #include <fstream>
  7.  
  8. using namespace std;
  9.  
  10. //Global Vars
  11. int mainMenuChoice = 0;
  12.  
  13.     // Player Info
  14.     string playerName = " ";
  15.     int playerHp = 100;
  16.     int playerHpMax = 100;
  17.     int playerDamage = 0;
  18.         int playerWeapon = 0;
  19.             // 0= fist, 1= rock, 2= hammer, 3= knife
  20.         string playerWeaponName = "Fists";
  21.         int playerWeaponAmmo = 0;
  22.             // 0= unlimited
  23.             int playerInvS[8];
  24.                 // 0 =none, 1= Alexandrovs ID, 2=
  25.             int playerInvSUsed = 0;
  26.                         /*  //AddInventoryItemCodeGroup
  27.                             playerInvS[playerInvSUsed] = 1; // added Alexandrovs ID to slot: #
  28.                             playerInvSUsed = playerInvSUsed + 1; // slot # filled */
  29.  
  30.  
  31. //voids
  32.     void options();
  33.     void mainMenu();
  34.     void startGame();
  35.     void loadGame();
  36.     void saveGame();
  37.     void loadGameRetieveText();
  38.     void selectChapter();
  39.     //voids game parts
  40.         void gamePart1();
  41.         void gamePart2();
  42.         void gamePart3();
  43.         void gamePart4();
  44.  
  45.         // void choices
  46.         void gP1R1();
  47.  
  48. //inizialize main
  49. int main()
  50. {
  51.     mainMenu();
  52.     std::cin.get();
  53.  
  54.     return 0;
  55. }
  56.  
  57. //init clock
  58. #include <time.h>
  59.  
  60. void wait ( double seconds )
  61. {
  62.   clock_t endwait;
  63.   endwait = clock () + seconds * CLOCKS_PER_SEC ;
  64.   while (clock() < endwait) {}
  65. }
  66.  
  67.  
  68.  
  69. //Options
  70.     // option vars
  71.     int optionsMenuChoice = 0;
  72.     int difficulty = 0;
  73.  
  74.         // START OPTIONS
  75.     void options()
  76.     {   //display menu
  77.         system("cls");
  78.         system("color 20");
  79.         cout << "           Options" << endl << endl;
  80.         cout << "Choose Option to change" << endl << endl;
  81.         cout << "1: Difficulty (Changes Difficulty)" << endl;
  82.         cout << "2: Return to Main Menu" << endl;
  83.         cin >> optionsMenuChoice;
  84.  
  85.         //menu choose
  86.         switch(optionsMenuChoice)
  87.         {
  88.             case 1:
  89.                 system("cls");
  90.                 cout << "Enter difficulty (1 = easy, 2 = hard)" << endl;
  91.                 cin >> difficulty;
  92.                 if (difficulty > 2 || difficulty < 1)
  93.                 {
  94.                     cout << "difficulty must be = to 1 or 2" << endl << "Difficult set to 1 as default" << endl;
  95.                     difficulty = 1;
  96.                 }
  97.                 else
  98.                     cout << "Difficulty set to "<<difficulty << endl;
  99.                     system("pause");
  100.                     system("cls");
  101.                     options();
  102.                 break;
  103.             case 2:
  104.                 system("cls");
  105.                 mainMenu();
  106.                 break;
  107.             default:
  108.                 system("cls");
  109.                 options();
  110.         }
  111.     }
  112.  
  113.     void startGame()
  114.     {
  115.         system("CLS");
  116.         cout << "1986, April 26:" << endl << " Chernobyl Power Plant, Soviet Controlled Ukraine " << endl << "1:10 A.M." << endl;
  117.         system("Pause");
  118.         cout << endl << "Inside Chernobyl Plant Lab 4 (Biological Studies)" << endl << endl << "Dr. Alexandrov : Titov! Bring me specimen 1734." << endl << "Titov: Yes Dr. Alexandrov"<< endl << "Titov quickly brought back a cage with a small mouse inside," << endl << " Dr. Alexandrov quickly put the mouse into a small box, " << endl << " and put the box into a slit vault door in the reactor" << endl;
  119.         system("Pause");
  120.         system("cls");
  121.         cout << "As Alexandrov closes the vault door, he notices a crack in the reactor" << endl << "He dismisses it as a minor flaw with no immenent consequence" << endl;
  122.         wait (10);
  123.         cout << "He was wrong" << endl;
  124.         system("Pause");
  125.         system("cls");
  126.         cout << "As the reactors power increased Alexandrov watched the mouse running into the walls of the box" << endl;
  127.         system("Pause");
  128.         system("cls");
  129.         cout << "The Box cracked under the pressure of the reactor, allowing the mouse to escape" << endl;
  130.         system("Pause");
  131.         system("cls");
  132.         cout << "Radioactive Energy also escaped from the crack, instantly vaporizing Dr. Alexandrov." << endl;
  133.         cout << "Titov saw the mouse running at him, he noticed its glow and its red eyes, its pounced up and bit Titov" << endl << "Titov pulled the mouse off and threw it away from him" << endl << "instantly feeling pain in his neck, and numbness all through his body" << endl;
  134.         system("Pause");
  135.         system("cls");
  136.         wait(5);
  137.         cout << "April 26, 1:30 A.M.: "<< endl <<"Titov then felt nothing, his eyes began to close as the reactor exploded." << endl << " The floor collapsed under him, and he fell into a dark hole and was covered in rubble." << endl;
  138.         system("Pause");
  139.         system("cls");
  140.         wait (2);
  141.         cout << "August 28, 2017:" << endl << "Chernobyl Radiation levels have decended to a safe enviorment, with radiation suits on off course." << endl << " Dr. Gregory and his team have just began searching the long destroyed reactor for" << endl << " evidence of what caused the chernobyl disaster" << endl;
  142.         system("Pause");
  143.         system("cls");
  144.         gP1R1();
  145.  
  146.     }
  147.  
  148.  
  149. void mainMenu()
  150. {
  151.     // Display Menu
  152.     system("cls");
  153.     system("color 20");
  154.     cout << "               Zombie Survival             " << endl << endl;
  155.     cout << "Select # for choice of game" << endl << endl;
  156.     cout << "1: New Game (Starts a brand new game)" << endl;
  157.     cout << "2: Load Game (Loads a Previously Saved game)" << endl;
  158.     cout << "3: Options (Selects Options)" << endl;
  159.     cout << "4: Exit (Exits the Program)" << endl;
  160.     cout << endl << endl << endl << endl << endl;
  161.     cout << "777777777777777777777777777777777777777777777777777777777IIIIIIIIIII777777777777"<< endl << "7777   7  7 7777777777777777777777777777777777777IIIIII777II7IIIIII7777777777777"<< endl << "777                         7777777 77 7       7 777777777777777777777  77777777"<< endl << "777                                               777777 777                7777"<< endl << "777                                                                         7777"<< endl << "7777                                                        ,,,7           77777"<< endl << "7777                                                      7,,,,,7          77777"<< endl << "7777                7,,,,7                               ,,,,,,77          77777"<< endl << "7II7                 ,,,,,,,,,=7I,,~                 7,,,,,,,,,,           77777"<< endl << "III7               ,,,,,,,,,,,,,,,,,.,              7,,,,,,,,,,,,          77777"<< endl << "III7            7,,,,,,,,,,,,,,,,?,,,,,7            7,,,,,,,,,,,,          77777"<< endl << "III7            ,,,,,,,,,,,,,,,,7 7 ,,,,7          7,,,,,,,,,,,,,,         77777"<< endl << "III7          ,,,,,,,,,,,,,,,,,,7  7 7.,,          ,,,7,,,,,,, I,,7        77777"<< endl << "II77       :,,,,,,,,,,,,,,,,,,,,+     7 ,         ?,, 7,,,,,,777,,7        77777"<< endl << "III7      ,,,,,,,77,,,,,,,,,,,,,,                7,,  7,,,,,, 7 7,,        77777"<< endl << "III7    ?,,,,7= 7  77,,,,,,,,,,,,,7             ,,,I  ,,,,,,,7   .,        77777"<< endl << "II77    7,,7,777    77,,,,,,,,,,,,,             ,~7 77,,,,,,,,   7,,       77777"<< endl << "II77      7 7, 7       ,,,,,,,,,,,?             ,=  77,,,,,,,,   7 ,       77777"<< endl << "II77         7        77,,,,,,,,,,=             ,7  77,,,,,,,,77 7,,       77777"<< endl << "III7                    .,,,7,,,,,              777 7~,,,7 ,,, 7 77,       77777"<< endl << "777                     ,,,,  ,,,,7                  ,,,,  ,,,7            77777"<< endl << "777                   7,,,,~  ,,,,                   ,,,=  ,,,?7         7777777"<< endl << "777                   =,,,,7   ,,,7                  ,,,7  I,,,       777  77777"<< endl << "777                 7 ,,,,.    ,,,~                  ,,,7  ?,,,       7777777777"<< endl << "777                  ,,,,~    7,,,,                  ,,,7   I,,      77777 77777"<< endl << "777                7,,,,, 7    I,,,                 7,,,   II,,7           77777"<< endl << "77                 7,,,,      7 ,,,                 7,,,7   I,,:           77777"<< endl << "77                 ,,,,         ,,,7                7,,,    7,,,   7       77777"<< endl << "77                :,,,77        :,,7                 ,,?    7?,,7  7       77777"<< endl << "77               7,,,           I,,,+              77,,,7   77,,7 777      77777"<< endl << "77               ,,,~            77=77           77,,,,?     7,,   7       77777"<< endl << "77              7=,, 7                           ,,,,77     77,,7   77     77777"<< endl << "77                                                7  77     77  777       777777"<< endl << "77                                                  7   77      77        777777"<< endl << "77  77   7 7    7    7                              7   7 77777777777   77777777"<< endl << "77777777777777777777777777777777777777777777777777777777777777777  777  77777777"<< endl << "77777777777777777777777777777777777777777777777777777IIIIIIIIIIIII??????II777777"<< endl << "77777777777777777777777777777777777777777777777777777777777777777777777I77777777";
  162.     cout << endl << endl;
  163.  
  164.     cin >> mainMenuChoice;
  165.  
  166.     // input
  167.     switch(mainMenuChoice)
  168.     {
  169.     case 1:
  170.         system("CLS");
  171.         selectChapter();
  172.         break;
  173.     case 2:
  174.         system("CLS");
  175.         //loadGameRetieveText();
  176.         options();
  177.         break;
  178.     case 3:
  179.         system("CLS");
  180.         options(); // brings to options
  181.         break;
  182.     case 4:
  183.         system("CLS");
  184.         exit (1);
  185.         break;
  186.     default:
  187.         system("cls");
  188.         mainMenu();
  189.         break;
  190.     }
  191.     system("pause");
  192.  
  193. }
  194.  
  195. /*
  196.  
  197. // Var for savedgame
  198.         int savePosition = 0;
  199.  
  200.         //save
  201.     void saveGame()
  202.     {
  203.       ofstream savegame ("SaveGamed.txt");
  204.        if (savegame.is_open())
  205.         {
  206.           savegame << savePosition;
  207.            savegame.close();
  208.         }
  209.      else
  210.        cout << "Unable to save";
  211.     }
  212.         //loadRetriveText
  213.     void loadGameRetieveText()
  214.     {string line;
  215.          ifstream savegame ("SaveGamed.txt");
  216.          if (savegame.is_open())
  217.          {
  218.              while (! savegame.eof() )
  219.            {
  220.                getline (savegame,line);
  221.            }
  222.              savegame.close();
  223.              loadGame();
  224.          }
  225.          else
  226.              cout << "Unable to open file";
  227.     }
  228.  
  229.     //load game
  230.     void loadGame()
  231.     {
  232.    
  233.     }
  234.  
  235.  
  236. int GetIntVal(string line)
  237. {
  238.   // NOTE: You should probably do some checks to ensure that
  239.   // this string contains only numbers. If the string is not
  240.   // a valid integer, zero will be returned.
  241.   savePosition = atoi(line.c_str());
  242.  
  243.   return(savePosition);
  244. }
  245.  
  246. */
  247.  
  248. //Choose chapter
  249.  
  250. int chapterChoose = 0;
  251.  
  252. void selectChapter()
  253. {
  254.     cout << "Choose Chapter" << endl << endl;
  255.     cout << "1 = Game Start" << endl << "2 = Unforseen Consequences" << endl << "3 = The Plague" << endl << "4 = Escape" << endl << "5 = Return to Main Menu" << endl;
  256.     cin >> chapterChoose;
  257.     switch(chapterChoose)
  258.     {
  259.         case 1:
  260.             cout << "Game Start Selected" << endl;
  261.             wait (1);
  262.             system("cls");
  263.             startGame(); // begin
  264.             break;
  265.         case 2:
  266.             cout << "Unforseen Consequences Selected" << endl;
  267.             wait (1);
  268.             system("cls");
  269.             gP1R1(); // part1
  270.             break;
  271.         case 3:
  272.             cout << "The Plauge Selected" << endl;
  273.             wait (1);
  274.             system("cls");
  275.              gP1R1(); // part 2
  276.             break;
  277.         case 4:
  278.             cout << "Escape" << endl;
  279.             wait (1);
  280.             system("cls");
  281.              gP1R1(); // part 3
  282.             break;
  283.         case 5:
  284.             cout << "Returning to menu" << endl;
  285.             wait (1);
  286.             system("cls");
  287.             selectChapter();
  288.             break;
  289.         default:
  290.             selectChapter(); // wrong input
  291.             break;
  292.     }
  293. }
  294.  
  295. //local vars for gP1R1
  296. int choice = 0;
  297. int search1P1 = 0;
  298. int search1P2 = 0;
  299.  
  300. void gP1R1()
  301. {
  302.     system("cls");
  303.     cout << "U";
  304.     wait(0.3);
  305.     cout << "n";
  306.     wait(0.3);
  307.     cout << "f";
  308.     wait(0.3);
  309.     cout << "o";
  310.     wait(0.3);
  311.     cout << "r";
  312.     wait(0.3);
  313.     cout << "s";
  314.     wait(0.3);
  315.     cout << "e";
  316.     wait(0.3);
  317.     cout << "e";
  318.     wait(0.3);
  319.     cout << "n";
  320.     wait(0.3);
  321.     cout << " ";
  322.     wait(0.3);
  323.     cout << "C";
  324.     wait(0.3);
  325.     cout << "o";
  326.     wait(0.3);
  327.     cout << "n";
  328.     wait(0.3);
  329.     cout << "s";
  330.     wait(0.3);
  331.     cout << "e";
  332.     wait(0.3);
  333.     cout << "q";
  334.     wait(0.3);
  335.     cout << "u";
  336.     wait(0.3);
  337.     cout << "e";
  338.     wait(0.3);
  339.     cout << "n";
  340.     wait(0.3);
  341.     cout << "c";
  342.     wait(0.3);
  343.     cout << "e";
  344.     wait(0.3);
  345.     cout << "s"<< endl;
  346.     wait(0.3);
  347.     cout << "Enter your name: ";
  348.     cin >> playerName;
  349.     getline (cin,playerName);
  350.     wait(2);
  351.     cout << "Gregory: \"" << playerName << ", While we set up the equiptment out here go look around the offices. If you need us, dont hesitate to come get us. \"" << endl;
  352.     wait(5);
  353.     system("pause");
  354.     system("cls");
  355.     cout << "You walk down the hall and see several doors, after trying them all you enter the only unlocked door" << endl;
  356.     wait(6);
  357.     system("pause");
  358.    
  359.     //search1
  360.     bool check1Search1 = false;
  361.     bool check1Search2 = false;
  362.     bool check1Search3 = false;
  363.     bool check1Search4 = false;
  364.     char userYesNo = 'N';
  365.    
  366.         while(search1P1 == 0)
  367.         {
  368.             system("cls");
  369.             cout << "You enter the room and see a computer on a desk, file cabinet and a trash bin." << endl;
  370.             cout << "What would you like to do? " << endl << " 1: Look at the computer" << endl << "2: Search the desk drawers" << endl << "3: Search the file cabinet" << endl << "4: Search the trash bin" << endl << "5: Leave the Room" << endl;
  371.             cin >> choice;
  372.             switch(choice)
  373.             {
  374.             case 1:
  375.                 if(check1Search1 == true)
  376.                 {
  377.                     cout << " You look at the computer again, nothing has changed." << endl;
  378.                     system("pause");
  379.                     break;
  380.                 }
  381.                 cout << "You look at the computer but the screen is cracked and the computer has no power supply" << endl;
  382.                 check1Search1 = true;
  383.                 system("pause");
  384.                 break;
  385.             case 2:
  386.                 if(check1Search2 == true)
  387.                 {
  388.                     if(check1Search4 == true)
  389.                     {
  390.                         cout << " The desk is covered in crumpled up papers from the trash bin." << endl;
  391.                         system("pause");
  392.                     }
  393.                     cout << " You search the desk again but dont find anything important." << endl;
  394.                     system("pause");
  395.                     break;
  396.                 }
  397.                 cout << " You search the desk, and find an ID belonging to a Dr. Alexandrov. You keep it for Gregory" << endl;
  398.                 //AddInventoryItemCodeGroup
  399.                 playerInvS[playerInvSUsed] = 1; // added Alexandrovs ID to slot: 1
  400.                 playerInvSUsed = playerInvSUsed + 1; // slot 1 filledb
  401.                 check1Search2 = true;
  402.                 system("pause");
  403.                 break;
  404.             case 3:
  405.                 if(check1Search3 == true)
  406.                 {
  407.                     cout << " You look through the file cabinets again, You look at the report again." << endl << "     Dr. Alexandrov: " << endl << "  Today we ran tests on 16 specimens, but specimen 1679 (21 day old mouse), and it began to shake uncontrollably and its eyes began to glow.\n    After increasing the internal power (to 200000 Watts for a total of 4 seconds), The mouse almost burst. The mouse then ran into the walls of the box\n  and fell onto its side. After de-contamination Titov pronounced it dead. Im looking forward to see another glowing in eyes of another \n    specimen. After another specimen experiences the same effects, we'll have multiple records of this occurring " << endl;
  408.                     system("pause");
  409.                     break;
  410.                 }
  411.                 cout << "You look through the file cabinet, and find a report on a series of tests run on small animals, it reads as follows" << endl << endl << "      Dr. Alexandrov: " << endl << "  Today we ran tests on 16 specimens, but specimen 1679 (21 day old mouse), and it began to shake uncontrollably and its eyes began to glow.\n    After increasing the internal power (to 200000 Watts for a total of 4 seconds), The mouse almost burst. The mouse then ran into the walls of the box\n  and fell onto its side. After de-contamination Titov pronounced it dead. Im looking forward to see another glowing in eyes of another \n    specimen. After another specimen experiences the same effects, we'll have multiple records of this occurring " << endl;
  412.                 check1Search3 = true;
  413.                 system("pause");
  414.                 break;
  415.             case 4:
  416.                 if(check1Search4 == true)
  417.                 {
  418.                     cout << " The trash can is empty from dumping the papers on the desk." << endl;
  419.                     system("pause");
  420.                     break;
  421.                 }
  422.                 cout << "You dump the crumpled up papers out on the desk, but dont find anything special" << endl;
  423.                 check1Search4 = true;
  424.                 system("pause");
  425.                 break;
  426.             case 5:
  427.                 if(check1Search2 == false || check1Search3 == false)
  428.                 {
  429.                     cout << "You didn't check everywhere, are you sure you want to leave? (Y/N) : ";
  430.                     cin >> userYesNo;
  431.                     userYesNo = toupper(toupper(userYesNo));
  432.                     if(userYesNo == 'N')
  433.                     {
  434.                         break;
  435.                     }
  436.                     if(userYesNo == 'Y')
  437.                     {
  438.                         search1P1 = 1;
  439.                         break;
  440.                     }
  441.                 }
  442.                 else
  443.                 {
  444.                     search1P1 = 1;
  445.                     cout << "You leave the room back into the hallway" << endl;
  446.                     break;
  447.                 }
  448.                 break;
  449.             default:
  450.                 system("cls");
  451.                 break;
  452.             }
  453.         }
  454.  
  455.         bool hasCrowbar = false;
  456.         bool check2Search1 = false;
  457.         bool check2Search2 = false;
  458.         bool check2Search3 = false;
  459.        
  460.         while(search1P2 == 0)
  461.         {
  462.             system("cls");
  463.             cout << " You enter the dark hallway and hear a deep grumble, ";
  464.             cout << "You look around and see a crate, toolbox, and a chair." << endl;
  465.             cout << "What would you like to do?" << endl;
  466.             cout << "1: Open the crate" << endl << "2: Search the toolbox" << endl << "3: Examine the chair" << endl << "4: Walk down the hall back to Dr. Gregory and the rest of the team" << endl;
  467.             cin >> choice;
  468.                 switch(choice)
  469.                 {
  470.                 case 1:
  471.                     if(check2Search1 == true)
  472.                     {
  473.                         if(hasCrowbar == false)
  474.                         {
  475.                         cout << "You attempt to pull the crate open again, but it will not budge" << endl;
  476.                         system("pause");
  477.                         break;
  478.                         }
  479.                         else
  480.                         {
  481.                             cout << "You pry the crate open with the crowbar, and search it. You find several cages with decayed mice inside" << endl;
  482.                             break;
  483.                         }
  484.                         cout << "You search the crate again, You find several cages with decayed mice inside. " << endl;
  485.                         break;
  486.                     }
  487.                     else
  488.                     {
  489.                         cout << "You try to pull the crate open, but fail. It will not open, you need a tool of some sort." << endl;
  490.                         break;
  491.                     }
  492.                     check2Search1 = true;
  493.                     break;
  494.                 case 2:
  495.                     if(check2Search2 == true)
  496.                     {
  497.                         cout << " You search the toolbox again but nothing else important is inside" << endl;
  498.                         system("pause");
  499.                         break;
  500.                     }
  501.                     cout << "You open the toolbox, and find a small crowbar. Maybe you can pry open the crate with it" << endl;
  502.                     hasCrowbar == true;
  503.                     check2Search2 = true;
  504.                     system("pause");
  505.                     break;
  506.                 case 3:
  507.                     cout << "You look at the chair, it is in bad condition. It looks very dangerous to sit in" << endl;
  508.                     if(check2Search2 == true)
  509.                     {
  510.                         cout << "The chair will break if you sit in it." << endl;
  511.                         system("pause");
  512.                         break;
  513.                     }
  514.                     check2Search3 = true;
  515.                     break;
  516.                 case 4:
  517.                     search1P2 = 1;
  518.                     break;
  519.                 }
  520.             }
  521.         cout << "You walk down the hall, and see the equiptment set up and some lights on" << endl;
  522.         wait(5);
  523.         cout << "But everyone is gone" << endl;
  524.         wait(2);
  525.         cout << "You hear the growl again" << endl;
  526.         system("pause");
  527.  
  528.        
  529. }
Advertisement
Add Comment
Please, Sign In to add comment