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 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
|
/**
*
* Word Jumble Application
* Made by: Ryan Wilson
* Date: 9/20/13 (2:49am)
* Date modified: 9/20/13 (3:49am)
*
*/
#include <iostream>
#include <string>
#include <ctime>
#include <algorithm>
using std::cout;
using std::endl;
using std::cin;
using std::string;
int main()
{
cout << "\t\t\tWelcome to Word Jumble!\n\n";
cout << "\tYou have 3 trys for each word, try to complete " <<
"as many\n \twords as you can for the best possible points. Good luck!\n\n";
cout << "Use 'hint' to get a hint of the word(-5 point " <<
"value for the word)\n";
cout << "Use 'quit' to exit the program\n";
enum wordData { WORD, HINT, NUM_FIELDS };
const int MAX_WORDS = 12;
const string WORD_LIST[MAX_WORDS][NUM_FIELDS] =
{
{"football", "NFL"},
{"wallet", "Carry cards and other small belongings"},
{"mcdonalds", "Where most fat kids go to"},
{"diablo", "Farm until you die."},
{"protein", "Helps you get buff"},
{"trashcan", "Throwing something away"},
{"feline", "Nine lives"},
{"computer", "Common electric device"},
{"bathroom", "\"Personal business\" area"},
{"marijuana", "Damnn dudes it's 420... light it up"},
{"keyboard", "Use for typing"},
{"bedroom", "Sleep here"},
};
/*
* Gets a word from the list to be guessed
* Creates a randomized string of the word
*/
srand((unsigned int) time(0));
const int randIndex = (rand() % MAX_WORDS);
string theWord = WORD_LIST[randIndex][WORD];
string theHint = WORD_LIST[randIndex][HINT];
string jumbledWord = "";
//cout << "\nJumbled word: " << jumbledWord << endl;
const int MAX_TRYS = 3;
int wordAttempts = 0;
int pointsToDecrease = 0;
string guess = "";
bool hintUsed = false;
int playerScore = 0;
while (guess != "quit" && wordAttempts < MAX_TRYS)
{
if (wordAttempts == 0 && guess != "quit" && guess != "hint")
{
jumbledWord = theWord;
std::random_shuffle(jumbledWord.begin(), jumbledWord.end());
cout << "\nJumbled word: " << jumbledWord << endl;
}
cout << "\nGuess: ";
cin >> guess;
if (guess == "hint")
if (hintUsed == false)
{
cout << "The hint: " << theHint << endl;
pointsToDecrease += 5;
hintUsed = true;
}
else
cout << "You already used your hint for this word!\n";
if (guess == theWord)
{
const int WORD_SCORE = (theWord.length() * 2);
const int RAND_INDEX = (rand() % MAX_WORDS);
cout << "Congratulations! The word was: " << theWord << ", +" << WORD_SCORE << " points.(-" << pointsToDecrease << " for hint usage)\n";
playerScore += (theWord.length() * 2) - pointsToDecrease;
cout << "You have a total of: " << playerScore << " points so far!\n";
//RESET VARIABLES FOR NEW WORD
theWord = WORD_LIST[RAND_INDEX][WORD];
theHint = WORD_LIST[RAND_INDEX][HINT];
wordAttempts = 0;
hintUsed = false;
pointsToDecrease = 0;
}
else
if (guess != "hint" && guess != "quit")
{
++wordAttempts;
wordAttempts < 3 ? cout << "Wrong try again! You have " << (MAX_TRYS - wordAttempts) << " trys left.\n" :
cout << "Game over, no more trys left! You earned a total of " << playerScore << " points!\n";
if (wordAttempts >= MAX_TRYS)
cout << "\nThe word was: " << theWord << endl;
}
}
cout << "\nPress any key to continue...";
cin.ignore();
cin.get();
}
|