After either you guess the state or you get ten strikes, the entire string is supposed to be cleared and restart and quit is supposed to appear and if you choose restart, the program starts from the top, but if you press quit the program ends. sometimes the code freezes when either of the two conditions are met, or everything will be cleared except for the input line and then it freezes. this is my first time using subprocedures so I think it is something to do with that.
restart:
cls:randomize timer ()
states:
`declare states
dim state$(50)
for s = 1 to 50
read state$(s)
next s
`pick random word
rndstate$ = state$(rnd(50))
`return amount of letters in word
statelen = len(rndstate$)
dim state(1,statelen)
`makes an `*` for a blank
blank$ = ""
for n = 1 to statelen
blank$ = blank$ + "*"
next n
`mistakes
strikes = 0
strike$ = "Strikes:"
`display
set text opaque:set text size 30
text 50,0, "United States Hangman"
text 50,100, rndstate$
text 50,150, blank$
text 73,280, str$(strikes)
text 50,240, strike$
`main loop
do
gosub playgame
gosub win
gosub lose
sync
loop
playgame:
set cursor 50,50
input "Type a letter and press enter - "; guess$
`incorrect answer variable
notwrong = 0
`check if the guessed letter is in the word
for letter = 1 to statelen
if mid$(rndstate$,letter) = guess$
blank$ = left$(blank$,letter-1) + mid$(rndstate$,letter) + right$(blank$,statelen-letter)
text 50,150, blank$
notwrong = 1
endif
next letter
`wrong answer
if notwrong = 0
strikes = strikes + 1
text 73,280, str$(strikes)
wrong = 1
endif
return
win:
if blank$ = rndstate$ and strikes<10
cls:sync on:sync rate 10
menu = 0
disable escapekey
text 50,0,"Congratulations!"
text 50,10,rndstate$
if menu = 0
text 50,0,"-restart-"
text 50,50,"quit"
endif
if menu = 1
text 50,0,"restart"
text 50,50,"-quit-"
endif
if menu = 0 and returnkey() = 1 then gosub restart
if menu = 1 and returnkey() = 1 then end
if upkey()=1 then inc menu
if downkey()=1 then dec menu
if menu > 1 then menu = 0
if menu < 0 then menu = 1
endif
return
lose:
if strikes>=10
cls:sync on:sync rate 10
menu = 0
disable escapekey
text 50,0,"Lamentations!"
if menu = 0
text 50,0,"-restart-"
text 50,50,"quit"
endif
if menu = 1
text 50,0,"restart"
text 50,50,"-quit-"
endif
if menu = 0 and returnkey() = 1 then gosub restart
if menu = 1 and returnkey() = 1 then end
if upkey()=1 then inc menu
if downkey()=1 then dec menu
if menu > 1 then menu = 0
if menu < 0 then menu = 1
endif
return
`declare the states
data "alabama"
data "alaska"
data "arizona"
data "arkansas"
data "california"
data "colorado"
data "connecticut"
data "delaware"
data "florida"
data "georgia"
data "hawaii"
data "idaho"
data "illinois"
data "indiana"
data "iowa"
data "kansas"
data "kentucky"
data "louisiana"
data "maine"
data "maryland"
data "massachusetts"
data "michigan"
data "minnesota"
data "mississippi"
data "missouri"
data "montana"
data "nebraska"
data "nevada"
data "newhampshire"
data "newjersey"
data "newmeixco"
data "newyork"
data "northcarolina"
data "northdakota"
data "ohio"
data "oklahoma"
data "oregon"
data "pennsylvania"
data "rhodisland"
data "southcarolina"
data "southdakota"
data "tennessee"
data "texas"
data "utah"
data "vermont"
data "virginia"
data "washington"
data "westviriginia"
data "wisconsin"
data "wyoming"