I am writing a hangman game code and I am having trouble defining, implement and correctly invoking these 3 functions exactly as declared below.
@brief Puts dashes in place of alphabetic characters in the phrase.
@param phrase the phrase to be solved
@return the phrase with all alphabetic characters converted to dashes
string setupUnsolved(string phrase);
@brief Replaces the dashes with the guessed character.
@param phrase the phrase to be solved
@param unsolved the phrase with dashes for all unsolved characters
@param guess the char containing the current guessed character
@return the new unsolved string with dashes replaced by new guess
string updateUnsolved(string phrase, string unsolved, char guess);
@brief Gets valid guess as input.
A guess is taken as input as a character. It is valid if
1) it is an alphabetic character; and
2) the character has not already been guessed
@param prevGuesses the string containing all characters guessed so far
@return a valid guess and only a valid guess as a character
char getGuess(string prevGuesses);
Here is what I have any suggestions or hints would be wonderful!
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
|
#include <iostream>
#include <iomanip>
#include <string>
#include "assn4.h"
using namespace std;
string setupUnsolvedPhrase(string);
string updateUnsolvedPhrase(string, string, char);
int main()
{
int wrongGuess = 0;
int guessesLeft = 7 - wrongGuess;
string phrase, prevGuesses;
char guess, validGuess;
cout << "Enter phrase: ";
getline(cin, phrase);
clearScreen();
string unsolved = setupUnsolvedPhrase(phrase);
cout << "Phrase : " << unsolved << endl;
cout << "Enter a guess: ";
cin >> guess;
unsolved = updateUnsolvedPhrase(phrase, unsolved, guess);
cout << endl;
while (phrase!=unsolved)
{
cout << "Phrase : " << unsolved << endl << endl;
cout << "Guessed so far: " << prevGuesses << endl;
cout << "Wrong guesses left: " << guessesLeft << endl << endl;
cout << "Enter a guess: ";
cin >> guess;
//getNewGuess(prevGuesses);
prevGuesses += guess;
cout << "Previous guesses: " << prevGuesses << endl;
unsolved = updateUnsolvedPhrase(phrase, unsolved, guess);
}
cout << "Congratulations!!" << endl;
}
string setupUnsolvedPhrase(string phrs){
//I think I need the definition here
return "";
}
string updateUnsolvedPhrase(string phrs, string unslvd, char g)
{
return "";
}
|