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
|
double game()
{
system("cls");
enum fields {WORD, HINT, NUM_FIELDS};
const int NUM_WORDS = 10; // Number of words I'm using to be mixed up.
const string WORDS[NUM_WORDS][NUM_FIELDS] =
{
{"automotive", "A field of mechanical engineering that specializes in automobiles."},
{"engineer"," A person who is professionally engaged in a field of machines."},
{"HVAC&R", " A field of mechanical engineering that specializes in aircon and refrigeration."},
{"mechatronics", " A field of mechanical engineering that specializes in robots."},
{"refrigerator", " An insulated, cooled compartment."},
{"machine", " A combination of rigid or resistant bodies having definite motions and capable of performing useful work."},
{"gear", " A mechanism performing a specific function in a machine."},
{"mesh", " Engagement or working contact of teeth of gears or of a gear and a rack."},
{"robot", "It is a mechanical or virtual intelligent agent that can perform tasks automatically or with guidance, typically by remote control."},
{"screw", "It is a type of fastener characterized by a helical ridge."},
};
int choice = (rand() % NUM_WORDS); // chooses a random number between 1-10 to choose a word from above
string theWord = WORDS[choice][WORD]; // word to guess
string theHint = WORDS[choice][HINT]; // hint for word
string jumble = theWord; // jumbled version of word
int length = jumble.size();
for(int i = 0; i < length; ++i)
{
int index1 = (rand() % length); // getting a random letter from the random word
int index2 = (rand() % length); // getting another letter from the random word
char temp = jumble[index1]; // Now I am switching those letters around so
jumble[index1] = jumble[index2]; // that they will be mixed up.
jumble[index2] = temp;
}
const int MAX_SCORE = 1100;
int players_score = 1000; // the player starts off with the highest score you can get
int guesses = 0;
cout << " Unscramble the letters to guess the right word. \n";
cout << "Enter 'hint' for a hint.\n";
cout << "Enter 'quit' quit the game. \n\n";
cout << "\n \t\t Your money: $" << players_score <<endl;
cout << "\n $150 for every hint"<<endl;
cout << " $200 for every wrong guess"<<endl;
cout << "Unscramble this word: " <<jumble<<endl;
string guess;
cout << "Your guess:\n ";
cin >> guess;
while((guess != theWord) && (guess != "quit"))
{
if(guess == "hint")
{
players_score -= 150; // If the player wants a hint, the players score will be deducted by ( the max score diveded by the number of letters in the random word.
cout << " \n\n \t\t\t You paid $150!"<< endl;
cout << " \n Your money is now: " << players_score << endl;
cout << " \n\n Here's the hint: \n";
cout << theHint;
}
else
{
++guesses;
players_score -= 200;
cout << "Sorry, thats not it.";
cout << "\n\n\t\t\t Your money is now: " << players_score;
}
cout << " \n\n Your guess: ";
cin >> guess;
}
if(guess == theWord)
{
players_score += 10;
cout << "\n Thats it! You guessed it!\n";
}
if(guess == "quit")
{
cout << " The unguessed word was " << theWord;
cout << " \n\n It took you " << guesses << " guesses. \n";
cout << " \n\n\t\t\t\t You have $" << players_score<<"! Congratulations!";
}
else if(players_score == MAX_SCORE)
cout <<"\n\n Great job, you kept alot of money!"<<endl;
cout <<"Thanks for playing."<<endl;
cin.get();
string response;
cout <<"\n\n\n Do you want to play again?[yes/no]";
cin >> response;
if (response=="yes")
game();
else
cout <<"\n\n Thanks for playing.Hope you enjoyed it. Good-bye";
cin.get();
return 0;
}
|