1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
//Word Jumble
//The classic word jumble game where the player can ask for a hint. Also can
//select difficulties: Easy, Normal, or Hard.
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
enum fields {WORDS, HINT, NUM_FIELDS};
enum difficulty {EASY, NORMAL, HARD};
const int NUM_WORDS = 5;
cout << "\t\t\tWelcome to Word Jumble!\n\n";
cout << "Unscramble the letters to make the word!\n";
cout << "Enter 'hint' for a hint!\n";
cout << "Enter 'quit' to make your computer explode... er, I mean quit the game!\n";
cout << "Now, choose your difficulty: \n\n";
cout << "1. Easy\n";
cout << "2. Normal\n";
cout << "3. Hard\n";
cin >> difficulty
if (difficulty == EASY)
const string WORDS[NUM_WORDS][NUM_FIELDS] =
{
{"wall", "Do you feel like you're banging your head against something?"},
{"glasses", "These might help you see the answer."},
{"labored", "Going slowly. Is it?"},
{"persistent", "Keep at it."},
{"jumble", "It's what this game is all about."},
};
if (difficulty == NORMAL)
const string WORDS[NUM_WORDS][NUM_FIELDS] =
{
{"Humpty Dumpty", "All the king's horses, and all the king's men..."},
{"withdraw", "Into his shell."},
{"whisper", "Don't let them overhear you!"},
{"playing", "What you are doing now."},
{"emuparadise", "A good emulation site and community."},
};
if (difficulty == HARD)
const string WORDS[NUM_WORDS][NUM_FIELDS] =
{
{"eulogy", "Tribute to the dead."},
{"zealot", "Fanatic."},
{"vigilante", "Operating outside the law, for the law."},
{"tournament", "Fight to the top!"},
{"pharaoh", "Ancient Egyptian king."},
};
srand(time(0));
int choice = (rand() % NUM_WORDS);
string theWORD = WORDS[choice][WORD]; //word to guess
string theHINT = WORDS[choice][HINT]; //hint to word
string jumble = theWORD; //jumbled version of word
int length = jumble.size();
for (int i = 0; i < length; ++i)
{
int index1 = (rand() % length);
int index2 = (rand() % length);
char temp = jumble[index1];
jumble[index1] = jumble[index2];
jumble[index2] = temp;
}
cout << "The jumble is: " << jumble;
string guess;
cout << "\n\nYour guess: ";
cin >> guess;
while ((guess != theWORD) && (guess != "quit"))
{
if (guess == "hint")
cout << theHINT;
else
cout << "Sorry, that's not correct.";
cout << "\n\nYour guess: ";
cin >> guess;
}
if (guess == theWORD)
cout << "\nThat's correct! You've won!\n";
cout << "\nThanks for playing!\n";
cout << "\n\nPress enter to exit.";
cin.get();
return 0;
}
| |