Replacing Strings - for Hangman
Author |
Message |
bigbut600
|
Posted: Sun Nov 23, 2008 6:13 pm Post subject: Replacing Strings - for Hangman |
|
|
Hey, guys, I have to make a hangman game, no graphics needed, where a person would enter a word, and another person guesses letters that might be in the word. The program has to display dashes (-) to represent the word.
For example-
It should look something like this:
Player 1 - Choose a word: ant
(clear screen)
---
Player 2 - The word has three letters. Choose a letter: e
e is not in the word
---
Player 2 - Choose a letter: a
You found a letter!
a--
Player 2 - Choose a letter: n
You found a letter!
an-
You have used up all your guesses... etc
That is what the program should do. But I am stuck on replacing letters entered by player 2 into the dashes that represent the word.
I need HELP big time on that. I'm not very good.
Can anyone please help me out?
This is what I have so far...not very much though. Please try running it on your computer. You would have to play as both Players though, to test it out.
code: |
var word : string
var option : int
var letter : string
var d3lay : string (1)
put "--HANGMAN GAME MENU--"
put "1) New Word"
put "2) Quit Game"
put " "
put "Player 1 - Choose an option: " ..
get option
if option = 1 then
cls
put "Player 1 - Choose a word: " ..
get word
cls
var newword : array 1 .. length (word) of string
for i : 1 .. length (word)
put "-" ..
end for
put " "
loop
put "Player 2 - The word has ", length (word), " letter(s). Choose a letter: " ..
get letter
if index (word, letter) = 0 then
put letter, " is not in the word."
else
put "You found a letter!"
end if
put " "
put "Hit any key to continue --->" ..
getch (d3lay)
cls
end loop
elsif option = 2 then
cls
put "Thanks for playing!"
end if
|
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
S_Grimm
|
Posted: Sun Nov 23, 2008 6:17 pm Post subject: RE:Replacing Strings - for Hangman |
|
|
Look into the Draw procedures. there is a draw text one that you could use. (ie draw the --- then when one is correct draw the a--, etc) use Booleans and ifs inside a loop. Procedures also might make your life easier. |
|
|
|
|
|
bigbut600
|
Posted: Sun Nov 23, 2008 6:29 pm Post subject: Re: RE:Replacing Strings - for Hangman |
|
|
A\V @ Sun Nov 23, 2008 6:17 pm wrote: Look into the Draw procedures. there is a draw text one that you could use. (ie draw the --- then when one is correct draw the a--, etc) use Booleans and ifs inside a loop. Procedures also might make your life easier.
I don't quite understand. I'm only allowed to use the things I've learned from school. Grade 10 Turing. All I know is that I've been learning how to replace strings before but none like this, because I never used something to represent a string before, in this case, the "-".
I thought of someways of how I can do this but I don't know how to code it.
1st) I was thinking of looking in the actual word, and seeing what position of the letter is in the word, and then go to the dashes, find that position, and replace it with the letter.
I don't know where to start coding from that. Any help? This seems to be the best way, in my point of view. |
|
|
|
|
|
S_Grimm
|
Posted: Sun Nov 23, 2008 6:56 pm Post subject: RE:Replacing Strings - for Hangman |
|
|
F10 is your new best friend. and without a whole lot of work, Drawing the font is easier.
But it can be done. what you need is a boolean variable FOR EACH LETTER. then when letter 1 is guessed, the boolean variable for that letter becomes true. that way, an if statement will be sufficient
Turing: |
if (Letter1 boolean variable = true) then
put "a"..
end if
if (Letter2 boolean variable = true) then
put "n"..
end if
%etc. etc. etc.
|
if your teacher hasn't taught you boolean variables and if statments, then he shouldn't be teaching. then are essential for any complex program. |
|
|
|
|
|
|
|