Advertisement
Guest User

Untitled

a guest
Mar 1st, 2013
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.05 KB | None | 0 0
  1. #include<iostream>
  2. #include<string>
  3. #include<cstdlib>
  4. #include<ctime>
  5.  
  6. using namespace std;
  7.  
  8. //Read user input
  9. //Parameters are acceptable choices
  10. int input(int c1 = 0,int c2 = 0,int c3 = 0,int c4 = 0,int c5 = 0,int c6 = 0)
  11. {
  12. int choice;
  13. if (cin >> choice)
  14. {
  15.  
  16. //Check if the user's input is a valid option for this scene
  17. if(choice == c1 || choice == c2 || choice == c3 || choice == c4 || choice == c5 || choice == c6)
  18. {
  19. //User's choice is valid
  20. cin.clear();
  21. cin.sync();
  22. return choice;
  23. }
  24. else if (choice == 9)
  25. {
  26. //Quit
  27. cin.clear();
  28. cin.sync();
  29. return 8;
  30. }
  31.  
  32. }
  33. else
  34. {
  35. //User's choice is not an integer
  36. cin.clear();
  37. cin.sync();
  38.  
  39. return 9;
  40. }
  41. }
  42.  
  43. int main()
  44. {
  45. //Declarations
  46. //Note: remember to declare AND DEFINE a variable for operating on it
  47. int stage = 0;
  48. int oldStage = 0;
  49. int selection = 0;
  50. bool done = false;
  51. char quit;
  52.  
  53. //Main loop
  54. do
  55. {
  56. switch(stage)
  57. {
  58. //Initial text
  59. case 0:
  60. cout << "You wake in at the bottom of a narrow chasm.\nA narrow beam of soft light weaves its way through the impenetrable walls above,\nreflected in shallow rivulets meandering across the chasm floor." <<endl;
  61. cout << "The walls of your stone casket are slick with rain.\nThe entire world is silent save for the distant songs of birds,\nand the soft howl of wind through the chasm." << endl;
  62. cout << "\nYou stand up and take in your surroundings." << endl;
  63. cout << "\nAs your eyes adjust, you find a narrow passage before you. Behind you lies a cramped tunnel." << endl;
  64. cout << "\n1 - Squeeze through the narrow passage.\n3 - Crawl through the mysterious tunnel.\n5 - Look around.\n6 - Help." << endl;
  65. oldStage = stage;
  66. stage = input(1,3,5,6);
  67. break;
  68. //transitory case
  69. case 1:
  70. cout << "\nYou squeeze through the passage...\n";
  71. system("pause");
  72. cout << endl << endl;
  73. stage = 2;
  74. break;
  75. case 2:
  76. cout << "You find yourself in a large cavern.\nThe interior is aglow with a blue ceiling of foxfire. Mushrooms light the cavern well enough to see its dimensions.";
  77. cout << "\nAt the center of the cavern is a cistern of clean water. It's too dark to gauge its depth, though it seems it could be bottomless.\n";
  78. cout << "\n1 - Explore the cavern.\n3 - Return through the passage.\n5 - Look around.\n6 - Help." << endl;
  79. oldStage = stage;
  80. selection = input(1,3,5,6);
  81. //Direct each valid choice to the proper stage
  82. switch(selection)
  83. {
  84. case 1:
  85. stage = 3;
  86. break;
  87. case 3:
  88. stage = 4;
  89. break;
  90. case 5:
  91. stage = 5;
  92. break;
  93. case 6:
  94. stage = 6;
  95. break;
  96. case 8:
  97. stage = 8;
  98. default:
  99. cout << "\nPlease input a valid integer.\n\n";
  100. stage = oldStage;
  101. system("pause");
  102. break;
  103. }
  104. //Another transitory case. these may become redundant...
  105. case 4:
  106. cout << "\nYou squeeze through the passage...\n";
  107. system("pause");
  108. cout << endl << endl;
  109. stage = 5;
  110. //Revisitation text
  111. case 5:
  112. cout << "You're back at the chasm's entrance.\n" << endl;
  113. cout << "\n1 - Squeeze through the narrow passage.\n3 - Crawl through the mysterious tunnel.\n5 - Look around.\n6 - Help.";
  114. oldStage = stage;
  115. selection = input(1,3,5,6);
  116. stage = selection;
  117. break;
  118. //Help case
  119. case 6:
  120. cout << "\nMovement: 1,2,3,4\nLook: 5\nQuit: 9\n";
  121. stage = oldStage;
  122. system("pause");
  123. break;
  124. //Quit case
  125. case 8:
  126. cin.clear();
  127. cin.sync();
  128. cout << "Leaving so soon? Y/N" << endl;
  129. cin >> quit;
  130. cout << quit;
  131. if (quit == 'Y')
  132. {
  133. done == true;
  134. }
  135. else
  136. {
  137. cout << "I thought you'd stick around."<< endl;
  138. stage = oldStage;
  139. }
  140. break;
  141. case 9:
  142. cout << "\nPlease input a valid integer.\n\n";
  143. stage = oldStage;
  144. system("pause");
  145. break;
  146. default:
  147. cout << "\nUnrecognized command.\n\n";
  148. stage = oldStage;
  149. system("pause");
  150. break;
  151. }
  152.  
  153.  
  154. }while(!done);
  155.  
  156.  
  157. cout << endl << "Thanks for playing!" << endl;
  158. system("pause");
  159. return 0;
  160. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement