Mar-30-2020, 01:01 AM
How would you do this with pencil and paper? Pretend you are playing this game with a friend. First you pick a secret word, "before" for example, and write the initial guess word replacing each letter in the secret word with "*":
Guess = ******
Your friend guesses "e" so you update the guess word to display:
Guess = *e***e
Your friend guesses "r" and you update the guess word to display:
Guess = *e***re
How did you do that? I did that by looking at the secret word, finding where my friend's letter guess matches letters in the secret word, and replacing "*" at those positions with the guessed letter. The game is won when there are no "*" in the guess word. The game is lost when max number of guesses is exceeded.
To translate to code lets first look for objects in the solution description (look for nouns). My solution uses the following objects:
secret word
letter guess
guess word
"*"
Next I look for actions:
pick
guess
finding
replace
The actions are things my program is going to do, and the objects are things my program is going to use.
The winning and losing criteria need some fleshing out to get nice objects and actions, but you've already got that part figured out I think.
Does that help?
Guess = ******
Your friend guesses "e" so you update the guess word to display:
Guess = *e***e
Your friend guesses "r" and you update the guess word to display:
Guess = *e***re
How did you do that? I did that by looking at the secret word, finding where my friend's letter guess matches letters in the secret word, and replacing "*" at those positions with the guessed letter. The game is won when there are no "*" in the guess word. The game is lost when max number of guesses is exceeded.
To translate to code lets first look for objects in the solution description (look for nouns). My solution uses the following objects:
secret word
letter guess
guess word
"*"
Next I look for actions:
pick
guess
finding
replace
The actions are things my program is going to do, and the objects are things my program is going to use.
The winning and losing criteria need some fleshing out to get nice objects and actions, but you've already got that part figured out I think.
Does that help?