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
|
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
string guess;
enum fields {WORD, HINT, NUM_FIELDS}; //enumeration sets const objects inside variable field and
const int NUM_WORDS = 10; //NUM_FIELDS holds number of fields in array as index is 2//
const string WORDS[NUM_WORDS][NUM_FIELDS] = //array sets up
{
{"wall", "Do you feel like you're banging your head against something?"},
{"glasses", "These might help you see the answer."},
{"laboured", "Going slowly, is it?"},
{"persistent", "Keep at it!"},
{"jumble", "It's what the game is all about."},
{"banana", "Careful you don't slip up."},
{"style", "By what you're wearing I can see you have none of this."},
{"life", "Sitting here playing this proves you don't have one of these."},
{"idiot", "If you neede a hint for this one you're one of these."},
{"books", "You should read a few, might help your jumbling."}
};
cout << "\t\tWelcome to Word Jumble!\n\n";
cout << "Unscramble the letters to make a word.\n";
cout << "10 points for every letter in the word, -10 points for using a hint.\n";
cout << "Enter 'hint' for a hint.\n";
cout << "Enter 'quit' to quit the game.\n\n";
int score = 0;
int round = 1;
random_shuffle(WORDS[0], WORDS[NUM_WORDS]);
do //sets up game loop until player types "quit"
{
string theWord = WORDS[round - 1][WORD];
string theHint = WORDS[round - 1][HINT];
string jumble = theWord;
int length = jumble.size();
for (int i = 0; i < length; ++i)
{
srand(time(0));
int index1 = (rand() % length);
int index2 = (rand() % length);
char temp = jumble[index1];
jumble[index1] = jumble[index2];
jumble[index2] = temp; //sets up jumbled version of word by picking random letters and swapping
} //them as many times as there are characters in the word//
int roundScore = theWord.length() * 10; //decides score for word//
cout << "Round: " << round << "\n";
cout << "Your score is: " << score << "\n";
cout << "This word is worth: " << theWord.length() * 10 << " points.\n";
cout << "The jumble is: " << jumble;
cout << "\n\nYour guess: ";
cin >> guess;
while ((guess != theWord) && (guess != "quit"))
{
if (guess == "hint")
{
cout << theHint;
roundScore = (theWord.length() * 10) - 10; //deducts points for using hint//
}
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";
score = score + roundScore; //adds score for this round to total score//
++round;
}
}
while (guess != "quit"); //ends loop if player enters quit//
cout << "\nThanks for playing.\n";
return 0;
}
|