Hi How Do,
I need to develop the logic to cause the body parts to display as incorrect letters are guessed and to display a you lose message when the body is complete.
That's all I've identified at the moment.
Since the original posting I've developed some code that starts the process, but doesn't work properly. I tried using the same basic logic as I did for the correct letter guesses with some different variables.
REM Project: Assignment 13 - The Hang-Man (Phase 4)
REM Created: 11/11/2005 9:30:41 PM
REM Author: Ralph Chandler
REM ***** Main Source File *****
REM
startofprogram:
cls
remstart
1. A thirteen element array for the words to be used in your hangman program.
2. A way to randomly select the word from the word list.
3. A way to get the length of the randomly selected word.
4. An "if statement" that will display the appropriate number of letter spaces under it.
5. Create and fill a variable length element array with the letters of the word that was
randomly selected.
6. Display the game title. Done
7. Display your gallows. Done
remend
rem inialize error variable = 0
bg = 0
rem Build an array with 13 words.
rem Four, three letter words, five, four letter words & four five letter words.
Dim word$(12)
word$(0)= "pen"
word$(1)= "urn"
word$(2)= "ski"
word$(3)= "sat"
word$(4)= "test"
word$(5)= "bait"
word$(6)= "rate"
word$(7)= "quit"
word$(8)= "lake"
word$(9)= "grate"
word$(10)= "scars"
word$(11)= "skean"
word$(12)= "grope"
number = random()
rem Identify number generated for trouble shooting
rem print number
letter$=word$(number)
rem print length for trouble shooting
rem print letter$
rem visually see word to compare with number generated and it's match in the array.
rem text 100, 100, word$(number)
rem compute length of word
length = len (letter$)
Rem pass the randomly selected word into working variable
rem display$ = word$(number)
Rem Create a variable element array to contain the letters of the item ramdomly selected. We
Rem will use the value in spaces(length) to determine the number of elements within the array.
dim itemletters$(length)
for c = 1 to (length)
itemletters$(C) = Mid$(letter$,c)
print itemletters$(c)
next c
if length = 3
threespace()
else
if length =4
fourspace()
else
fivespace()
endif
endif
Rem Display the title.
Title()
Rem Display the gallows.
gallows()
rem retur:
rem okay:
input "Guess a letter ",guess$
rem goto check
rem Initalize flag variable = 0
rem User entry of qq will quit the program
while guess$ <> "qq"
rem Initialize a flag variable
letterguess = 0
rem Create nested if/then/else logic to compare user guess to letter array for a match
for d = 1 to length
if guess$ = itemletters$(d) and d=1
text 135,425, guess$
letterguess = letterguess + 1
else
if guess$ = itemletters$(d) and d=2
text 185,425, guess$
letterguess = letterguess + 1
else
if guess$ = itemletters$(d) and d=3
text 235,425, guess$
letterguess = letterguess + 1
else
if guess$ = itemletters$(d) and d=4
text 285,425, guess$
letterguess = letterguess + 1
else
if guess$ = itemletters$(d) and d=5
text 335,425, guess$
letterguess = letterguess + 1
else bg = bg+1
endif
endif
endif
endif
endif
next d
for d=1 to length
if guess$ <> itemletters$(d) and d=1
head()
bg = bg + 1
else
if guess$ <> itemletters$(d) and d=2
body()
bg = bg + 1
else
if guess$ <> itemletters$(d) and d=3
rarm()
bg = bg + 1
else
if guess$ <> itemletters$(d) and d=4
larm()
bg = bg + 1
else
if guess$ <> itemletters$(d) and d=5
rleg()
bg = bg + 1
if guess$ <> itemletters$(d) and d=6
lleg()
bg = bg + 1
endif
endif
endif
endif
endif
endif
next d
rem Print the you win message.
if letterguess = length
youwin()
endif
if letterguess = length
goto startofprogram
endif
input "Guess a letter ",guess$
endwhile
rem This ends the program and must be present before the function declarations
end
function Title()
rem Define the font, size of title. Identifies game title name.
set text font "comic sans ms"
set text size 36
ink rgb(0, 255, 0), 0
text 120, 40, "Welcome to Hang-Man"
ink rgb(255, 0, 0), 0
text 120, 42, "Welcome to Hang-Man"
set text size normal
ink rgb(0, 255, 0), 0
endfunction
function gallows()
rem Draw post
line 175, 125, 175, 375
rem draw bar
line 175, 125, 275, 125
rem draw rope
line 275, 125, 275, 175
endfunction
function head()
rem draw the head
circle 275, 190, 15
endfunction
function body()
line 275, 205, 275, 260
endfunction
function lleg()
rem Draw left leg
line 275, 260, 300, 310
endfunction
function rleg()
rem Draw right leg
line 275, 260, 250, 310
endfunction
function larm()
rem Draw left arm
line 275, 205, 300, 245
endfunction
function rarm()
rem Draw right arm
line 275, 205, 250, 245
endfunction
function threespace()
rem 1st letter space
Line 125, 450, 150, 450
rem 2nd letter space
Line 175, 450, 200, 450
rem 3rd letter space
Line 225, 450, 250, 450
endfunction
function fourspace()
rem 1st letter space
Line 125, 450, 150, 450
rem 2nd letter space
Line 175, 450, 200, 450
rem 3rd letter space
Line 225, 450, 250, 450
rem 4th letter space
Line 275, 450, 300, 450
endfunction
function fivespace()
rem 1st letter space
Line 125, 450, 150, 450
rem 2nd letter space
Line 175, 450, 200, 450
rem 3rd letter space
Line 225, 450, 250, 450
rem 4th letter space
Line 275, 450, 300, 450
rem 5th letter space
Line 325, 450, 350, 450
endfunction
function random()
rem Number generator for chose a word at random
randomize timer()
number = rnd(12)
endfunction number
function youwin()
cls
for win=1 to 30
wait 50
text rnd(450), rnd(450), "you Win"
next win
endfunction
function youlose()
cls
for win=1 to 30
wait 50
text rnd(450), rnd(450), "You Lose the word was " + letter$
next win
endfunction
remstart
check:
if itemletters$(c) <> guess$
goto retur
else
if itemletters$(c) = guess$
goto okay
endif
endif
remend