Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Text-based-game/jumble.cpp
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
93 lines (68 sloc)
2.19 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "jumble.h" | |
using namespace std; | |
int jumble() | |
{ | |
PlayerMenu playermenu; | |
Sql sql; | |
int score; | |
score = 0; | |
enum fields { WORD, HINT, NUM_FIELDS }; | |
const int NUM_WORDS = 9; | |
const string WORDS[NUM_WORDS][NUM_FIELDS] = | |
{ | |
{ "wall", "Do you feel like banging your head against something?" }, | |
{ "glasses", "These might help you see the answer" }, | |
{ "persistant", "keep at it" }, | |
{ "jumble", "It's what the game is all about!", }, | |
{ "decorate", "Add to something to make it more attractive", }, | |
{ "Rome", "Capital of Italy, " }, | |
{ "advocate", "A person who pleads for a person, cause, or idea", }, | |
{ "sanguine", "Confidently optimistic and cheerful", }, | |
{ "didactic", "Instructive with a moral intent", } | |
}; | |
srand(time(0)); | |
int choice = (rand() % NUM_WORDS); | |
string theWord = WORDS[choice][WORD]; //word to guess | |
string theHint = WORDS[choice][HINT]; //hint | |
//to jumble the word | |
string jumble = theWord; //jumbled version of the 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; | |
score = length; // score based on the length of the word | |
} | |
// welcome the player | |
cout << "\t\tWelcome to Word Jumble\n\n"; | |
cout << "Let's start our game\n"; | |
cout << "Unscarmble the letters to make a word.\n"; | |
cout << "Enter 'hint' for a hint.\n"; | |
cout << "Enter 'quit' to quit the game\n\n"; | |
cout << "The jumble is " << jumble; | |
string guess; | |
cout << "\n\nYour guess: "; | |
cin >> guess; | |
//entering the game loop | |
while ((guess != theWord) && (guess != "quit")) | |
{ | |
if (guess == "hint") | |
cout << theHint; | |
else | |
cout << "Sorry! That is not the correct word..."; | |
--score; //subtracts points for hint or if you guess wrong | |
cout << "\n\nYour guess: "; | |
cin >> guess; | |
} | |
if (guess == theWord) | |
{ | |
cout << "\nThat's it! Congrats!! You guessed it! You have a score of " << score << endl; | |
sql.updateBalanceCleaningTable(); | |
cout << "\nThanks for playing!\n"; | |
playermenu.ppmenu(); | |
} | |
return 0; | |
} |