-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjumble.cpp
85 lines (60 loc) · 1.87 KB
/
jumble.cpp
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
// jumble
// word jumble game
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
using namespace std;
void welcomePlayer() {
cout << "\t\t\tWelcome to Wrod Jumble!" << endl << endl;
cout << "Unscramble the letters to make the correct word." << endl;
cout << "Enter 'hint' for a hint, and 'quit' to give up." << endl << endl;
}
string jumbleWord(string originalWord) {
string jumble = originalWord;
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;
}
return jumble;
}
int main() {
enum fields {WORD, HINT, NUM_FIELDS};
const int NUM_WORDS = 5;
const string WORDS[NUM_WORDS][NUM_FIELDS] =
{
{"wall", "Do you feel you're banging your head against someting?"},
{"glasses", "These might help you see the answer."},
{"jumble", "It's what the game is all about."},
{"test", "This might feel like one."},
{"christmas", "Santa clause is coming to town."}
};
srand(static_cast<unsigned int>(time(0)));
int choice = (rand() % NUM_WORDS);
string theWord = WORDS[choice][WORD];
string theHint = WORDS[choice][HINT];
string jumble = jumbleWord(theWord);
welcomePlayer();
cout << "The jumble is " << jumble;
string guess = "empty";
cout << "\n\nYour Guess :";
cin >> guess;
while ((guess != theWord) && (guess != "quit")) {
if (guess == "hint") {
cout << theHint;
} else {
cout << "Sorry, that's not it.";
}
cout << "\n\nYour Guess :";
cin >> guess;
}
if (guess == theWord) {
cout << "\nThat's it! You guessed it!\n\n";
}
cout << "\nThanks!";
return 0;
}