Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.78 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <stdlib.h>
  4. #include <string>
  5. #include <fstream>
  6. #include "../Character/char_creation.h"
  7. #include "../Character/char_sheet.h"
  8. #include "../GameStory/intro.h"
  9.  
  10. using namespace std;
  11.  
  12. void in_game_actions();
  13. void game_help();
  14. void game_save();
  15. void game_load();
  16. void invalid_input();
  17. string menu_action;
  18. int story_progress;
  19.  
  20.  
  21. void main()
  22. {
  23. system("CLS");
  24. string main_menu_comm;
  25. cout << "Welcome to the development of the text based game!" << endl;
  26. cout << "------------------New game (N)-----------------" << endl;
  27. cout << "------------------Load game (L)----------------" << endl;
  28. retry:
  29. cin >> main_menu_comm;
  30.  
  31. if (main_menu_comm == "N" || main_menu_comm == "n" || main_menu_comm == "New" || main_menu_comm == "new") {char_creation();}
  32. else if (main_menu_comm == "L" || main_menu_comm == "l" || main_menu_comm == "Load" || main_menu_comm == "load") {game_load();}
  33. else {goto retry;}
  34. }
  35.  
  36. void in_game_actions()
  37. {
  38.  
  39. start:
  40. char confirmation;
  41. char action[50];
  42. cin >> action;
  43.  
  44. switch (action[0])
  45. {
  46. case 'C': case 'c': player.player_info_full(); goto start;
  47.  
  48. case 'M' : case 'm':
  49. cout << "Do you wish to return to the main menu?" << endl;
  50. cin >> confirmation;
  51. if (confirmation == 'Y' || confirmation == 'y') {main();}
  52. else {goto start;}
  53.  
  54. case 'S': case 's':
  55. cout << "Do you wish to save the game?" << endl;
  56. cin >> confirmation;
  57. if (confirmation == 'Y' || confirmation == 'y') {game_save(); goto start;}
  58. else {goto start;}
  59.  
  60. case 'H': case 'h': game_help(); goto start;
  61. case 'E': case 'e': switch (action[1])
  62. {
  63. case 'X': case 'x': menu_action = "exit"; break;
  64. case 'N': case 'n': if (action[5] != '-') {invalid_input();}
  65. switch (action[6])
  66. {
  67. case 'C': case 'c': menu_action = "castle"; break;
  68. }
  69. } break;
  70.  
  71. case 'L': case 'l': menu_action = "look"; break;
  72.  
  73. case 'R': case 'r': menu_action = "rest"; break;
  74.  
  75. case 'P': case 'p': if (action[4] != '-') {invalid_input();}
  76. switch (action[5])
  77. {
  78. case 'P': case 'p': menu_action = "pitchfork"; break;
  79. case 'A': case 'a': menu_action = "axe"; break;
  80. } break;
  81.  
  82. }
  83. }
  84.  
  85. void invalid_input()
  86. {
  87. cout << "Invalid input. Type 'help' for support." << endl;
  88. in_game_actions();
  89. }
  90.  
  91. void game_help()
  92. {
  93. cout << "___________________HELP___________________" << endl;
  94. cout << "These commands can be lower or upper case:" << endl;
  95. cout << " " << endl;
  96. cout << "Main Menu (Main)" << endl;
  97. cout << "Save Game (Save)" << endl;
  98. cout << "Character Pane (Char)" << endl;
  99. cout << "Inventory (Inv)" << endl;
  100. cout << " " << endl;
  101. cout << "The following commands have to be ALL lowercase with the exception of the initial letter:" << endl;
  102. cout << " " << endl;
  103. cout << "== Every character action has to be typed with at least the first two letters. Example: 'exit' can be typed as 'ex', 'exi' or 'exit' but NOT 'e'." << endl;
  104. cout << endl;
  105. cout << "== If action involves two stages, such as enter ___ or pick up ___ then you have to type the character action followed " << endl << "by '-' and then the item/location. Example: pick-axe, enter-town." << endl;
  106. cout << "_________________END HELP_________________" << endl;
  107. }
  108.  
  109. void game_save()
  110. {
  111. ofstream savefile;
  112. savefile.open("save_game.txt");
  113. if (savefile.is_open()
  114. {
  115. savefile << player.playername << endl;
  116. savefile << player.playergender << endl;
  117. savefile << player.playerage << endl;
  118. savefile << player.playerstatus << endl;
  119. savefile << player.playerclass << endl;
  120. savefile << HP << endl;
  121. savefile << Strength << endl;
  122. savefile << Dexterity << endl;
  123. savefile << Charisma << endl;
  124. savefile << Speech << endl;
  125. savefile << story_progress << endl;
  126. savefile.close();
  127. cout << "Game saved." << endl;
  128. }
  129. else {cout << "Error saving game. Please try again." << endl;}
  130. }
  131.  
  132. void game_load()
  133. {
  134. ifstream loadfile;
  135. loadfile.open("save_game.txt");
  136. if (loadfile.is_open())
  137. {
  138. cout << "Game loaded. Returning to your last checkpoint." << endl;
  139. loadfile >> player.playername;
  140. loadfile >> player.playergender;
  141. loadfile >> player.playerage;
  142. loadfile >> player.playerstatus;
  143. loadfile >> player.playerclass;
  144. loadfile >> HP;
  145. loadfile >> Strength;
  146. loadfile >> Dexterity;
  147. loadfile >> Charisma;
  148. loadfile >> Speech;
  149. loadfile >> story_progress;
  150. loadfile.close();
  151. system("pause");
  152. system("CLS");
  153. intro(story_progress);
  154. }
  155. else { cout << "Error opening file. Please try again." << endl; system("pause"); main(); }
  156. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement