Posted: 21st Nov 2011 23:26
I need some help. I am trying to add a way for my program to accept upper or lower case letters and I am also trying to figure out how to get the system to detect if a letter has previously been guessed. Here is a copy of the code that I have written so far. Any helpwould be greatly apprecaited.
My Code:
startofprogram:
cls
dim wordlist(12) as string
num as integer
gitem as string
li as integer
found as string
Error as integer
guess as string
usedletters as integer
letterguess as integer
undim itemletters()
dim itemletters(5) as string
wordlist(0) = "ant"
wordlist(1) = "bat"
wordlist(2) = "car"
wordlist(3) = "dog"
wordlist(4) = "eggs"
wordlist(5) = "food"
wordlist(6) = "good"
wordlist(7) = "help"
wordlist(8) = "inks"
wordlist(9) = "jacks"
wordlist(10) = "kiwis"
wordlist(11) = "limes"
wordlist(12) = "maker"
randomize timer()
title()
gallows()
num = rnd(12)
gitem = wordlist(num)
print gitem
li = len(gitem)
if li = 3
threeSpace()
else
if li = 4
threeSpace()
fourSpace()
else
threeSpace()
fourSpace()
fiveSpace()
endif
endif
for c = 1 to li
itemletters(c) = mid$(gitem,c)
next c
input "Guess a letter or press qq to quit: ", guess
while guess<> "qq"
found = "no"
if guess = itemletters(1)
text 115,380, guess
usedletters = usedletters + 1
found = "yes"
endif
if guess = itemletters(2)
text 170,380, guess
usedletters = usedletters + 1
found = "yes"
endif
if guess = itemletters(3)
text 215,380, guess
usedletters = usedletters + 1
found = "yes"
endif
if guess = itemletters(4)
text 265,380, guess
usedletters = usedletters + 1
found = "yes"
endif
if guess = itemletters(5)
text 305, 380, guess
usedletters = usedletters + 1
found = "yes"
endif
if usedletters = li
sleep 200
CLS
Winner()
sleep 1000
goto startofprogram
endif
if found = "no" and Error = 0
head()
Error = Error +1
else
if found = "no" and Error = 1
body()
Error = Error +1
else
if found = "no" and Error = 2
rleg()
Error = Error +1
else
if found = "no" and Error = 3
lleg()
Error = Error +1
else
if found = "no" and Error = 4
rarm()
Error = Error +1
else
if found = "no" and Error = 5
larm()
Error = Error +1
endif
endif
endif
endif
endif
endif
if Error = 6
sleep 200
cls
Lose()
sleep 1000
goto startofprogram
endif
input "Guess a letter or press QQ to quit: ", guess
endwhile
end
function title()
set text font "Chiller"
set text size 45
ink rgb(255,0,0),0
text 200,45, "Welcome to Hangman!!!"
ink rgb (0,0,255),0
text 201,46, "Welcome to Hangman!!!"
set text size 25
ink rgb(0,255,0),0
endfunction
function Winner()
set text font "Chiller"
set text size 45
ink rgb(255,0,0),0
text 200,45, "You win!!! You win!!!"
ink rgb (0,0,255),0
text 201,46, "You win!!! You win!!!"
endfunction
function Lose()
set text font "Chiller"
set text size 45
ink rgb(255,0,0),0
text 200,45, "You Lose!!!"
ink rgb (0,0,255),0
text 201,46, "You Lose!!!"
endfunction
function gallows()
line 200,100,200,320
line 200,100,300,100
line 300,100,300,150
endfunction
function head()
circle 300,160,10
endfunction
function body()
line 300,172,300,210
endfunction
function rleg()
line 300,210,290,250
endfunction
function lleg()
line 300,210,310,250
endfunction
function rarm()
line 300,172,310,210
endfunction
function larm()
line 300,172,290,210
endfunction
function threeSpace()
line 100,400,130,400
line 150,400,180,400
line 200,400,230,400
endfunction
function fourSpace()
line 250,400,280,400
endfunction
function fiveSpace()
line 300,400,330,400
endfunction
function LetterWrong(sLetter$)
bOutput as boolean = 1
for c = 1 to array count(itemletters(0))
if itemletters(c) = sLetter$
bOutput = 0
exit
endif
next c
endfunction bOutput
function HandleError(errors)
inc errors
select errors
case 1
head()
endcase
case 2
body()
endcase
case 3
rleg()
endcase
case 4
lleg()
endcase
case 5
rarm()
endcase
case 6
larm()
endcase
endselect
endfunction errors
wait key
end