userxbw

boardgame c++ for someone

Apr 20th, 2023
929
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 9.27 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <ctime>
  4. #include <vector>
  5. #include <cmath>
  6. #include <cstdlib>
  7. #include <iomanip>
  8.  
  9. using std::cout,std::cin,std::endl,std::string;
  10.  
  11. string PuzzleHint(string hint, string answer) {
  12.     hint = answer.at(0);
  13.     cout << "\n Hint: Starts with the letter " << hint << endl;
  14.     cout << "Your guess: ";
  15.     return hint;
  16. }
  17.  
  18. int GuessCorrectly(int score) {
  19.     score = score+1;
  20.     cout << "Congratulations! You got it correct. You got one point. \n ";
  21.     cout << "Would you like to play again?(yes/no): ";
  22.     return score;
  23. }
  24.  
  25. /*
  26.  
  27. string crossWord1() {
  28.    
  29. }
  30.  
  31. string crossWord2() {
  32.    
  33. }
  34.  
  35. string crossWord3() {
  36.    
  37. }
  38.  
  39. string crossWord4() {
  40.    
  41. }
  42. */
  43.  
  44. // this is not inside of loop so it is not being called to print again
  45.   // make it a function then call that function within the loop at the
  46.   // approate spot to print it again.
  47.   // to do:
  48.   // make it actually print "random" words
  49.   // needs a bank of real words ( words stored in an array would work)
  50.   // to be selected in a "random" form
  51.   // then "random" letters to be printed around the word in the matrix
  52.   // word to be randomly printed out forward, backward, and on a diangle
  53.   //pattern.
  54.  
  55.   void random_word() {
  56.   cout << "****************************Word Search Puzzle**************************** \n \n";
  57.  
  58.   cout << "A randomly generated puzzle is printed on the screen."
  59.   << " The\npuzzle has a word which varies in length. If the word is\nguessed correctly"
  60.   << " you will gain a point. \n\n\n";
  61.  
  62.   cout << "a b q g h u m e a y \n"
  63.   << "l j e v x a f i r c \n"
  64.   << "t v s e p g n b w k \n"
  65.   << "n d u f n f i t i j \n"
  66.   << "z v s r j o c w r a \n"
  67.   << "l i m e o y m c r t \n"
  68.   << "b r e n g q p e d j \n"
  69.   << "s a r p n g g u l p \n"
  70.   << "u j n q a n l k r y \n"
  71.   << "c u w a m h w l x e \n"
  72.   << "n d q k n r k f l q \n"
  73.   << "q t e g n a r o u q \n\n\n";
  74.  
  75.   cout << "****************************************************************************" << endl;
  76. }
  77. int main () {
  78.   int wordLength;
  79.   int score;
  80.   string userGuess;
  81.   string userPlayAgain;
  82.   int threeLetterWord;
  83.   int fourLetterWord;
  84.   int fiveLetterWord;
  85.   int sixLetterWord;
  86.   string answer;
  87.   string hint;
  88.  
  89.  
  90.  
  91.   score = 0;
  92.   srand (time (0));
  93.   wordLength = rand () % (6 - 3 + 1) + 3;
  94.    do {
  95.       random_word();
  96.       if (wordLength == 3) {
  97.       cout << "Find the " << wordLength << " letter word. \n";
  98.       threeLetterWord = rand() % 2 + 1;
  99.       if (threeLetterWord == 2) {
  100.           answer = "bee";
  101.           cout << "Your guess(type hint for a clue): ";
  102.           getline(cin, userGuess);
  103.           if (userGuess == "hint") {
  104.                  PuzzleHint(hint, answer);
  105.                  cin >> userGuess;
  106.                  // prevent from
  107.                  //skipping over cin
  108.                  std::cin.ignore(10, '\n');
  109.           }
  110.           if (userGuess == "bee") {
  111.         cout << endl;
  112.         score = GuessCorrectly(score);
  113.         cout << endl;
  114.          cin >> userPlayAgain;
  115.          cout << endl;
  116.          std::cin.ignore(10, '\n');
  117.           }
  118.          else {
  119.             cout << "\n That was incorrect.\n"
  120.             << "Would you like to play again(yes/no): ";
  121.             cin >> userPlayAgain;
  122.             cout << endl;
  123.             std::cin.ignore(10, '\n');
  124.          }
  125.       }
  126.       }
  127.       if (threeLetterWord == 1) {
  128.           answer = "ant";
  129.           cout << "Your guess(type hint for a clue): ";
  130.           getline(cin, userGuess);
  131.           if (userGuess == "hint") {
  132.                  PuzzleHint(hint, answer);
  133.                  cin >> userGuess;
  134.                  std::cin.ignore(10, '\n');
  135.       }
  136.       if (userGuess == "ant") {
  137.           cout << endl;
  138.           score = GuessCorrectly(score);
  139.           cin >> userPlayAgain;
  140.           cout << endl;
  141.           std::cin.ignore(10, '\n');
  142.       }
  143.       else {
  144.             cout << "\n That was incorrect.\n"
  145.             << "Would you like to play again(yes/no): ";
  146.             cin >> userPlayAgain;
  147.             cout << endl;
  148.             std::cin.ignore(10, '\n');
  149.          }
  150.       }
  151.       if (wordLength == 4) {
  152.        cout << "Find the " << wordLength << " letter word.\n";
  153.        fourLetterWord = rand() % 2 + 1;
  154.       if (fourLetterWord == 2) {
  155.           answer = "kiwi";
  156.           cout << "Your guess(type hint for a clue): ";
  157.           getline(cin, userGuess);
  158.           if (userGuess == "hint") {
  159.                  PuzzleHint(hint, answer);
  160.                  cin >> userGuess;
  161.                  std::cin.ignore(10, '\n');
  162.       }
  163.       if (userGuess == "kiwi") {
  164.           cout << endl;
  165.           score = GuessCorrectly(score);
  166.           cin >> userPlayAgain;
  167.           cout << endl;
  168.           std::cin.ignore(10, '\n');
  169.       }
  170.       else {
  171.             cout << "\n That was incorrect.\n"
  172.             << "Would you like to play again(yes/no): ";
  173.             cin >> userPlayAgain;
  174.             cout << endl;
  175.             std::cin.ignore(10, '\n');
  176.          }
  177.       }
  178.       if (fourLetterWord == 1) {
  179.           answer = "lime";
  180.           cout << "Your guess(type hint for a clue): ";
  181.           getline(cin, userGuess);
  182.           if (userGuess == "hint") {
  183.                  PuzzleHint(hint, answer);
  184.                  cin >> userGuess;
  185.                  std::cin.ignore(10, '\n');
  186.       }
  187.       if (userGuess == "lime") {
  188.           cout << endl;
  189.           score = GuessCorrectly(score);
  190.           cin >> userPlayAgain;
  191.           cout << endl;
  192.           std::cin.ignore(10, '\n');
  193.       }
  194.       else {
  195.             cout << "\n That was incorrect.\n"
  196.             << "Would you like to play again(yes/no): ";
  197.             cin >> userPlayAgain;
  198.             cout << endl;
  199.             std::cin.ignore(10, '\n');
  200.          }
  201.       }
  202.          
  203.       }
  204.       if (wordLength == 5) {
  205.       cout << "Find the " << wordLength << " letter word.\n";
  206.      fiveLetterWord = rand() % 2 + 1;
  207.       if (fiveLetterWord == 2) {
  208.           answer = "lemon";
  209.           cout << "Your guess(type hint for a clue): ";
  210.           getline(cin, userGuess);
  211.           if (userGuess == "hint") {
  212.                  PuzzleHint(hint, answer);
  213.                  cin >> userGuess;
  214.                  std::cin.ignore(10, '\n');
  215.       }
  216.       if (userGuess == "lemon") {
  217.           cout << endl;
  218.           score = GuessCorrectly(score);
  219.           cin >> userPlayAgain;
  220.           cout << endl;
  221.           std::cin.ignore(10, '\n');
  222.       }
  223.       else {
  224.             cout << "\n That was incorrect.\n"
  225.             << "Would you like to play again(yes/no): ";
  226.             cin >> userPlayAgain;
  227.             cout << endl;
  228.          }
  229.       }
  230.       if (fiveLetterWord == 1) {
  231.           answer = "mango";
  232.           cout << "Your guess(type hint for a clue): ";
  233.           getline(cin, userGuess);
  234.           if (userGuess == "hint") {
  235.                  PuzzleHint(hint, answer);
  236.                  cin >> userGuess;
  237.                  std::cin.ignore(10, '\n');
  238.       }
  239.       if (userGuess == "mango") {
  240.           cout << endl;
  241.           GuessCorrectly(score);
  242.           cin >> userPlayAgain;
  243.           cout << endl;
  244.       }
  245.       else {
  246.             cout << "\n That was incorrect.\n"
  247.             << "Would you like to play again(yes/no): ";
  248.             cin >> userPlayAgain;
  249.             cout << endl;
  250.             std::cin.ignore(10, '\n');
  251.          }
  252.       }
  253.       }
  254.      if (wordLength == 6) {
  255.     cout << "Find the " << wordLength << " letter word.\n";
  256.     sixLetterWord = rand() % 2 + 1;
  257.       if (sixLetterWord == 2) {
  258.           answer = "orange";
  259.           cout << "Your guess(type hint for a clue): ";
  260.           getline(cin, userGuess);
  261.           if (userGuess == "hint") {
  262.                  PuzzleHint(hint, answer);
  263.                  cin >> userGuess;
  264.                  std::cin.ignore(10, '\n');
  265.       }
  266.       if (userGuess == "orange") {
  267.           cout << endl;
  268.           score = GuessCorrectly(score);
  269.           cin >> userPlayAgain;
  270.           cout << endl;
  271.           std::cin.ignore(10, '\n');
  272.       }
  273.       else {
  274.             cout << "\n That was incorrect.\n"
  275.             << "Would you like to play again(yes/no): ";
  276.             cin >> userPlayAgain;
  277.             cout << endl;
  278.             std::cin.ignore(10, '\n');
  279.          }
  280.       }
  281.       if (sixLetterWord == 1) {
  282.           answer = "banana";
  283.           cout << "Your guess(type hint for a clue): ";
  284.           getline(cin, userGuess);
  285.           if (userGuess == "hint") {
  286.                  PuzzleHint(hint, answer);
  287.                  cin >> userGuess;
  288.                  std::cin.ignore(10, '\n');
  289.       }
  290.       if (userGuess == "banana") {
  291.           cout << endl;
  292.           score = GuessCorrectly(score);
  293.           cin >> userPlayAgain;
  294.           cout << endl;
  295.           std::cin.ignore(10, '\n');
  296.       }
  297.       else {
  298.             cout << "\n That was incorrect.\n"
  299.             << "Would you like to play again(yes/no): ";
  300.             cin >> userPlayAgain;
  301.             cout << endl;
  302.             std::cin.ignore(10, '\n');
  303.  
  304.          }
  305.       }
  306.      }
  307.      wordLength = rand () % (6 - 3 + 1) + 3;
  308.  
  309.   }
  310.     while(userPlayAgain != "no");
  311.    
  312.   //  if (userPlayAgain != "no") {
  313.         cout << "Your total score was: " << score;
  314.         cout << "\n Thank you for playing! \n";
  315.    // }
  316.  
  317.   return 0;
  318. }
  319.  
Advertisement
Add Comment
Please, Sign In to add comment