Jun 2, 2013 at 9:52pm UTC
Hello,
So I need help in designing an algorithm that will help me in my Hangman game.
I've got everything I need that is expected of my program except this.
When the user starts the game they will have these letters available to them:
"abcdefghijklmnopqrstuvwxyz"
Now if they were to guess 'a' it should look like this:
"-bcdefghijklmnopqrstuvwxyz"
then if they were to guess 'k':
"-bcdefghij-lmnopqrstuvwxyz"
and so forth.
Any ideas? or hints towards the right direction?
Thanks in advance!
Last edited on Jun 2, 2013 at 10:37pm UTC
Jun 2, 2013 at 10:44pm UTC
You can make string array/vector to store the letter's.
To access the element for a specific letter, subtract 65 for lower case, 97 for
upper case.
The result will give you the array/vector element.
If the content's of an element = '-', It has already been used.
Jun 2, 2013 at 10:44pm UTC
Initialize a std::list<char> with all the alphabets, one element one alphabet. Prompt user input. find() the list for user input. If found, erase the element and insert a '-' in it's place.
Jun 3, 2013 at 11:21pm UTC
This is what I have so far
1 2 3 4 5 6 7 8 9 10 11 12 13 14
void removeLetter(string &availableLetters, char guess)
{
int i = 0, found = 0;
string newSetOfLetters;
while (!found && i < availableLetters.length())
{
if (guess == availableLetters[i])
newSetOfLetters = string availableLetters.size(), "-" ;
}
return ;
}
obviously it doesn't work but it's all I could come up with.
Help would be appreciated!
Edit: I won't be able to use the two suggestions already given because those concepts haven't been covered. Thank you though.
Last edited on Jun 3, 2013 at 11:29pm UTC