Advertisement
Guest User

Untitled

a guest
Feb 13th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.79 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <cmath>
  4. #include <algorithm>
  5. #include <cstdlib>
  6.  
  7. using namespace std;
  8.  
  9. void game_prompt(int &number_players, int &number_rounds){
  10. cout << "Enter number of players: ";
  11. cin >> number_players;
  12. cout << "Enter the number of rounds: ";
  13. cin >> number_rounds;
  14. }
  15.  
  16. void initial_input(string &secret_message, string &word_display){
  17. cin.ignore();
  18.  
  19. cout << "Enter the secret message: ";
  20. getline(cin, secret_message);
  21. transform(secret_message.begin(), secret_message.end(), secret_message.begin(), ::toupper);
  22.  
  23. for (int i = 0; i < secret_message.length(); i++){
  24. if (secret_message[i] == ' '){
  25. word_display.append(" ");
  26. }
  27. else {
  28. word_display.append("_ ");
  29. }
  30. }
  31. }
  32.  
  33. void balance_management(int player, int money_count[3][2], int money, int purpose){
  34. /*
  35. purpose 1: add/subtract money
  36. purpose 2: move round money to game money and clears round money
  37. purpose 3: clear round money
  38. */
  39.  
  40. if (purpose == 1) {
  41. money_count[player-1][0] = money_count[player-1][0] + money;
  42. }
  43. else if(purpose == 2){
  44. money_count[player-1][1] = money_count[player-1][1] + money_count[player-1][0];
  45. money_count[player-1][0] = 0;
  46. }
  47. else if(purpose == 3){
  48. money_count[player-1][0] = 0;
  49. }
  50. }
  51.  
  52. bool solve_puzzle(string secret_message){
  53. cin.ignore();
  54.  
  55. string word_guess;
  56. cout << "What is your guess: ";
  57. getline(cin,word_guess);
  58. transform(word_guess.begin(), word_guess.end(), word_guess.begin(), ::toupper);
  59.  
  60. if (word_guess == secret_message){
  61. cout << "Congratulations! You guessed the phrase: " << secret_message << endl;
  62. return true;
  63. }
  64. else {
  65. cout << "That is not the correct phrase" << endl;
  66. return false;
  67. }
  68.  
  69. }
  70.  
  71. void player_roll(string secret_message, string word_display, int money_count[3][2], int player){
  72. int roll = rand()%21, multiplier;
  73. cout << "Roll: " << roll << endl;
  74. char consonant;
  75.  
  76. if (roll == 0){
  77. balance_management(player, money_count, 0, 3);
  78. }
  79. else if (roll == 21){
  80. //end the turn prematurely
  81. }
  82. else {
  83. //guess a non-vowel. For each correct, increase 'multiplier' by 1
  84. //set round money == round money * multiplier
  85. //edit word display to hold the correct values
  86. cout << "Guess a consonant: ";
  87. cin >> consonant;
  88. consonant = toupper(consonant);
  89. for (int i = 0; i < secret_message.length(); i++){
  90. if (secret_message[i] == consonant){
  91. multiplier++;
  92. word_display[2*i+1] = consonant;
  93. balance_management(player, money_count, roll*multiplier, 1);
  94. }
  95. }
  96. }
  97.  
  98. }
  99.  
  100.  
  101. char vowel_purchase(int money_count[3][2], int &b){
  102. char vowel;
  103. if (money_count[b-1][0] >= 10){
  104. balance_management(b, money_count, -10, 1);
  105. while(true){
  106. cout << "Enter a vowel: ";
  107. cin >> vowel;
  108. vowel = toupper(vowel);
  109. switch(vowel){
  110. case 'A':
  111. case 'E':
  112. case 'I':
  113. case 'O':
  114. case 'U':
  115. case 'Y':
  116. cin.ignore();
  117. return vowel;
  118. default:
  119. cout << "Not a valid input" << endl;
  120. break;
  121. }
  122. }
  123. }
  124. else{
  125. cout << "You do not have enough money" << endl;
  126. b--;
  127. cin.ignore();
  128. return '.'; //Since I have to have a return a value, I return "."
  129. }
  130. }
  131.  
  132. ///*
  133.  
  134. void player_turn(int money_count[3][2], int &b, string secret_message, string word_display, bool &cont){
  135. int option = 4;
  136. cout << "1 - Solve the Puzzle" << endl << "2 - Purchase a Vowel" << endl << "3 - Roll the dice" << endl;
  137. while(true){
  138. cout << endl << "What would you like to do: ";
  139. cin >> option;
  140. cin.ignore();
  141. if (option == 1){
  142. cont = solve_puzzle(secret_message);
  143. break;
  144. }
  145. else if (option == 2){
  146. vowel_purchase(money_count, b);
  147. break;
  148. }
  149. else if (option == 3){
  150. player_roll(secret_message, word_display, money_count, b);
  151. break;
  152. }
  153. else{
  154. cout << "Not a valid option" << endl;
  155. }
  156. }
  157. }
  158.  
  159. void display(){
  160.  
  161. }
  162.  
  163. void word_display_edit(string word_display, string secret_message, char chr){
  164.  
  165. }
  166.  
  167. //*/
  168.  
  169. int main(){
  170. srand(time(NULL));
  171. //Variable Declarations
  172. string secret_message, word_display;
  173. int number_players, number_rounds, money_count[3][2] = {16};
  174. bool cont;
  175.  
  176. game_prompt(number_players, number_rounds);
  177.  
  178.  
  179. for(int a = 1; a <= number_rounds; a++){
  180. cont == false;
  181. word_display = " "; //technically there will be a space in front of the word at all times
  182. initial_input(secret_message, word_display);
  183.  
  184. while(cont == false){
  185. for(int b = 1;b <= number_players; b++){
  186. player_turn(money_count, b, secret_message, word_display, cont);
  187. if (cont == true){
  188. break;
  189. }
  190. }
  191. if(cont == true){
  192. break;
  193. }
  194. }
  195. }
  196.  
  197. //testing
  198. //game_prompt(1,secret_message, word_display, number_players, number_rounds);
  199.  
  200. bool check = solve_puzzle(secret_message);
  201. cout << secret_message << endl;
  202. cout << word_display << endl;
  203. //end testing
  204.  
  205. return 0;
  206. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement