Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <ctime>
- #include <vector>
- #include <cmath>
- #include <cstdlib>
- #include <iomanip>
- using std::cout,std::cin,std::endl,std::string;
- string PuzzleHint(string hint, string answer) {
- hint = answer.at(0);
- cout << "\n Hint: Starts with the letter " << hint << endl;
- cout << "Your guess: ";
- return hint;
- }
- int GuessCorrectly(int score) {
- score = score+1;
- cout << "Congratulations! You got it correct. You got one point. \n ";
- cout << "Would you like to play again?(yes/no): ";
- return score;
- }
- /*
- string crossWord1() {
- }
- string crossWord2() {
- }
- string crossWord3() {
- }
- string crossWord4() {
- }
- */
- // this is not inside of loop so it is not being called to print again
- // make it a function then call that function within the loop at the
- // approate spot to print it again.
- // to do:
- // make it actually print "random" words
- // needs a bank of real words ( words stored in an array would work)
- // to be selected in a "random" form
- // then "random" letters to be printed around the word in the matrix
- // word to be randomly printed out forward, backward, and on a diangle
- //pattern.
- void random_word() {
- cout << "****************************Word Search Puzzle**************************** \n \n";
- cout << "A randomly generated puzzle is printed on the screen."
- << " The\npuzzle has a word which varies in length. If the word is\nguessed correctly"
- << " you will gain a point. \n\n\n";
- cout << "a b q g h u m e a y \n"
- << "l j e v x a f i r c \n"
- << "t v s e p g n b w k \n"
- << "n d u f n f i t i j \n"
- << "z v s r j o c w r a \n"
- << "l i m e o y m c r t \n"
- << "b r e n g q p e d j \n"
- << "s a r p n g g u l p \n"
- << "u j n q a n l k r y \n"
- << "c u w a m h w l x e \n"
- << "n d q k n r k f l q \n"
- << "q t e g n a r o u q \n\n\n";
- cout << "****************************************************************************" << endl;
- }
- int ran_num(){
- return (rand () % (6 - 3 + 1) + 3);
- }
- int main () {
- int wordLength;
- int score;
- string userGuess;
- string userPlayAgain;
- int threeLetterWord;
- int fourLetterWord;
- int fiveLetterWord;
- int sixLetterWord;
- string answer;
- string hint;
- score = 0;
- srand (time (0));
- do {
- random_word();
- switch (ran_num()) { //wordLength
- case 3:
- // debugging
- cout<<"in 3\n";
- cout << "Find the 3 letter word. \n";
- threeLetterWord = rand() % 2 + 1;
- cout<<threeLetterWord<<endl;
- //if (threeLetterWord == 2) {
- switch ( threeLetterWord ) {
- case 2:
- answer = "bee";
- cout << "Your guess(type hint for a clue): ";
- //getline(cin, userGuess);
- cin>>userGuess;
- if (userGuess == "hint") {
- PuzzleHint(hint, answer);
- cin >> userGuess;
- }
- if (userGuess == "bee") {
- cout << endl;
- score = GuessCorrectly(score);
- cout << endl;
- cin >> userPlayAgain;
- cout << endl;
- // to stop it from skipping over cin
- std::cin.ignore(10, '\n');
- } else {
- cout << "\n That was incorrect.\n"
- << "Would you like to play again(yes/no): ";
- cin >> userPlayAgain;
- cout << endl;
- std::cin.ignore(10, '\n');
- }
- break;
- case 1:
- //if (threeLetterWord == 1) {
- answer = "ant";
- cout << "Your guess(type hint for a clue): ";
- getline(cin, userGuess);
- if (userGuess == "hint") {
- PuzzleHint(hint, answer);
- cin >> userGuess;
- std::cin.ignore(10, '\n');
- }
- if (userGuess == "ant") {
- cout << endl;
- score = GuessCorrectly(score);
- cin >> userPlayAgain;
- cout << endl;
- std::cin.ignore(10, '\n');
- } else {
- cout << "\n That was incorrect.\n"
- << "Would you like to play again(yes/no): ";
- cin >> userPlayAgain;
- cout << endl;
- std::cin.ignore(10, '\n');
- }
- break;
- default:
- break;
- }
- //}
- break;
- case 4:
- // if (wordLength == 4) {
- // debugging
- cout<<"in 4\n";
- cout << "Find the 4 letter word.\n";
- fourLetterWord = rand() % 2 + 1;
- //if (fourLetterWord == 2) {
- switch (fourLetterWord) {
- case 2:
- answer = "kiwi";
- cout << "Your guess(type hint for a clue): ";
- getline(cin, userGuess);
- if (userGuess == "hint") {
- PuzzleHint(hint, answer);
- cin >> userGuess;
- std::cin.ignore(10, '\n');
- }
- if (userGuess == "kiwi") {
- cout << endl;
- score = GuessCorrectly(score);
- cin >> userPlayAgain;
- cout << endl;
- std::cin.ignore(10, '\n');
- } else {
- cout << "\n That was incorrect.\n"
- << "Would you like to play again(yes/no): ";
- cin >> userPlayAgain;
- cout << endl;
- std::cin.ignore(10, '\n');
- }
- break;
- // }
- //if (fourLetterWord == 1) {
- case 1:
- answer = "lime";
- cout << "Your guess(type hint for a clue): ";
- getline(cin, userGuess);
- if (userGuess == "hint") {
- PuzzleHint(hint, answer);
- cin >> userGuess;
- std::cin.ignore(10, '\n');
- }
- if (userGuess == "lime") {
- cout << endl;
- score = GuessCorrectly(score);
- cin >> userPlayAgain;
- cout << endl;
- std::cin.ignore(10, '\n');
- } else {
- cout << "\n That was incorrect.\n"
- << "Would you like to play again(yes/no): ";
- cin >> userPlayAgain;
- cout << endl;
- std::cin.ignore(10, '\n');
- }
- break;
- default:
- break;
- }
- //}
- break;
- case 5:
- // debugging
- cout<<"in 5\n";
- //if (wordLength == 5) {
- cout << "Find the 5 letter word.\n";
- fiveLetterWord = rand() % 2 + 1;
- //does not always give you a 2
- //so now you're getting wrong
- //answer even when no anwser
- //has been given
- //debugging
- cout<<fiveLetterWord<<endl;
- // if (fiveLetterWord == 2) {
- switch (fiveLetterWord) {
- case 2:
- answer = "lemon";
- cout << "Your guess(type hint for a clue): ";
- getline(cin, userGuess);
- if (userGuess == "hint") {
- PuzzleHint(hint, answer);
- cin >> userGuess;
- std::cin.ignore(10, '\n');
- }
- if (userGuess == "lemon") {
- cout << endl;
- score = GuessCorrectly(score);
- cin >> userPlayAgain;
- cout << endl;
- std::cin.ignore(10, '\n');
- } else {
- cout << "\n That was incorrect.\n"
- << "Would you like to play again(yes/no): ";
- cin >> userPlayAgain;
- cout << endl;
- std::cin.ignore(10, '\n');
- }
- //}
- break;
- //if (fiveLetterWord == 1) {
- case 1:
- answer = "mango";
- cout << "Your guess(type hint for a clue): ";
- getline(cin, userGuess);
- if (userGuess == "hint") {
- PuzzleHint(hint, answer);
- cin >> userGuess;
- std::cin.ignore(10, '\n');
- }
- if (userGuess == "mango") {
- cout << endl;
- score = GuessCorrectly(score);
- cin >> userPlayAgain;
- cout << endl;
- std::cin.ignore(10, '\n');
- } else {
- cout << "\n That was incorrect.\n"
- << "Would you like to play again(yes/no): ";
- cin >> userPlayAgain;
- cout << endl;
- std::cin.ignore(10, '\n');
- }
- break;
- default:
- break;
- }
- //}
- break;
- case 6:
- // debugging
- cout<<"in 6\n";
- // if (wordLength == 6) {
- cout << "Find the 6 letter word.\n";
- sixLetterWord = rand() % 2 + 1;
- //if (sixLetterWord == 2) {
- switch (sixLetterWord) {
- case 2:
- answer = "orange";
- cout << "Your guess(type hint for a clue): ";
- getline(cin, userGuess);
- if (userGuess == "hint") {
- PuzzleHint(hint, answer);
- cin >> userGuess;
- std::cin.ignore(10, '\n');
- }
- if (userGuess == "orange") {
- cout << endl;
- score = GuessCorrectly(score);
- cin >> userPlayAgain;
- cout << endl;
- std::cin.ignore(10, '\n');
- } else {
- cout << "\n That was incorrect.\n"
- << "Would you like to play again(yes/no): ";
- cin >> userPlayAgain;
- cout << endl;
- std::cin.ignore(10, '\n');
- }
- break;
- //}
- case 1:
- //if (sixLetterWord == 1) {
- answer = "banana";
- cout << "Your guess(type hint for a clue): ";
- getline(cin, userGuess);
- if (userGuess == "hint") {
- PuzzleHint(hint, answer);
- cin >> userGuess;
- std::cin.ignore(10, '\n');
- }
- if (userGuess == "banana") {
- cout << endl;
- score = GuessCorrectly(score);
- cin >> userPlayAgain;
- cout << endl;
- std::cin.ignore(10, '\n');
- } else {
- cout << "\n That was incorrect.\n"
- << "Would you like to play again(yes/no): ";
- cin >> userPlayAgain;
- cout << endl;
- std::cin.ignore(10, '\n');
- }
- break;
- default:
- break;
- }
- //}
- break;
- default:
- break;
- }
- // }
- // wordLength = rand () % (6 - 3 + 1) + 3;
- } // end outer switch
- while(userPlayAgain != "no");
- // not needed if kick out of loop then game over
- // just print results
- // if (userPlayAgain != "no") {
- cout << "Your total score was: " << score;
- cout << "\n Thank you for playing! \n";
- //}
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment