Posted: 25th Nov 2013 20:17
This is the code I have for the program. I need to have a variable for alreadyusedletters that is compared to the userguess 1-10. If userguess 2 is = to userguess 1, then text "duplicate letter". If userguess 3 is = to userguess 1 and/or 2, then text "duplicate letter, etc. This duplicate guess should not count against the player as a wrong answer or using up one of their guesses.
I would greatly appreciate any help in figuring out how to write this code and where to put it. I have to have this completed by Friday, 11/29.
Thanks!
`global settings
startofprogram:
cls
randomize timer()
`declare variables -
dim words(12) as string
randomnum as integer
workingword as string
length as integer
counter as integer
undim letters()
dim letters(5) as string
userguess as string
validletter as integer
found as string
error as integer
`validcounter as integer
`assign values
words(0)="bog"
words(1)="orb"
words(2)="yap"
words(3)="boa"
words(4)="hawk"
words(5)="stir"
words(6)="cyst"
words(7)="shot"
words(8)="acme"
words(9)="cheat"
words(10)="fired"
words(11)="yummy"
words(12)="point"
randomnum=rnd(12)`randomonly picks a word from the list 0-12
workingword=words(randomnum) `says the randomly picked word is word x
length=len(workingword) `length of word
`dynamic allocation
for counter=1 to length
letters(counter)=mid$(workingword,counter)
` print letters(counter) `for beta testing only - take this out for final
next counter
`game processing and display
title()
gallows()
print workingword
if length=3
threespace()
else
if length=4
fourspace()
else
fivespace()
endif
endif
ink rgb(139,69,19),0
set text font "Ariel"
set text size 18
set text to normal
set cursor 0,298
input "Guess a letter ";userguess
while userguess <>"qq"
found="no"
userguess=Lower$(userguess)
ink rgb(128,128,0),0
set text font "Chiller"
set text size 52
if userguess=letters(1)
text 255,410,userguess
validletter = validletter +1
found="yes"
endif
if userguess=letters(2)
text 300,410,userguess
validletter = validletter +1
found="yes"
endif
if userguess=letters(3)
text 345,410,userguess
validletter=validletter+1
found="yes"
endif
if userguess=letters(4)
text 390,410,userguess
validletter=validletter+1
found="yes"
endif
if userguess=letters(5)
text 435,410,userguess
validletter=validletter+1
found="yes"
endif
`winning routine
if validletter=length
sleep 500
cls
ink RGB(255,255,0),0
set text font "Chiller"
set text size 60
text 10,10,"WINNER!!!"
`ink RGB(255,140,0),0
`set text font "Arial"
`set text size 1000
`text 400,75,"*"
`ink RGB(199,21,133),0
`set text font "Arial"
`set text size 1000
`text 420,120,"*"
`ink RGB(123,104,238),0
`set text font "Times"
`set text size 2000
`text 375,100,"*"
ink RGB(255,0,192),0
set text font "Impact"
set text size 75
text 71,75,"Way to go!"
ink RGB(255,0,0),0
set text font "Chiller"
set text size 85
text 152,170,"WINNER!!!"
ink RGB(0,255,255),0
set text font "Arial"
set text size 85
text 230,255,"Great job!"
ink RGB(128,225,0),0
set text font "Chiller"
set text size 75 `60
text 293,345,"WINNER!"
ink RGB(156,22,245),0
set text font "Impact"
set text size 60
text 415,420,"You did it!"
sleep 3000
cls
goto startofprogram:
endif
`error routines
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
larm()
error=error+1
else
if found="no" and error=3
rarm()
error=error+1
else
if found="no" and error=4
rleg()
error=error+1
else
if found="no" and error=5
lleg()
error=error+1
sleep 1000
endif
endif
endif
endif
endif
endif
if error=6
cls
`sleep 100
set text font "Arial"
set text size 36
text 100,100,"Your word was " + workingword
sleep 1000
cls
ink RGB(255,0,0),0
set text font "Chiller"
set text size 65
text 10,10,"LOSER!!!"
ink RGB(255,140,0),0
set text font "Arial"
set text size 250
text 71,65,"Poor baby!"
ink RGB(199,21,133),0
set text font "Chiller"
set text size 85
text 152,170,"LOSER!!!"
ink RGB(123,104,238),0
set text font "Times"
set text size 60
text 223,255,"Not so smart, huh!"
ink RGB(0,206,209),0
set text font "Chiller"
set text size 95
text 293,327,"LOSER!!!"
ink RGB(124,252,0),0
set text font "Impact"
set text size 40
text 350,427,"Better luck next time!"
sleep 3000
cls
sleep 2000
cls
goto startofprogram:
endif
ink rgb(139,69,19),0
set text font "Ariel"
set text size 18
set text to normal
input "Guess another letter ";userguess ` these are always the last 2 lines of program
`secondary input - when have prime input like first guess, you have to have a second
`input or you will have endless loop
endwhile
`wait key
end
function title()
ink rgb(128,128,0),0
set text font "Chiller"
set text size 52
set text to bold
text 215,25,"Welcome to Hangman"
endfunction
function gallows()
ink rgb(128,0,0),0
line 400,100,400,350
line 401,100,401,350
line 402,100,402,350
line 403,100,403,350
line 404,100,404,350
line 405,100,405,350
line 406,100,406,350
line 407,100,407,350
line 408,100,408,350
line 409,100,409,350
line 400,100,300,100
line 400,101,300,100
line 400,102,300,100
line 400,103,300,100
line 400,104,300,100
line 400,105,300,100
line 400,106,300,100
line 400,107,300,100
line 400,108,300,100
line 400,109,300,100
line 300,100,300,155
line 300,100,301,155
line 300,100,302,155
line 300,100,303,155
line 300,100,304,155
line 300,100,305,155
line 300,100,306,155
line 300,100,307,155
line 300,100,308,155
line 300,100,309,155
line 455,350,345,350
line 455,351,345,351
line 455,352,345,352
line 455,353,345,353
line 455,354,345,354
line 455,355,345,355
line 455,356,345,356
line 455,357,345,357
line 455,358,345,358
line 455,359,345,359
endfunction
function head()
ink rgb(255,215,0),0
circle 300,175,20
circle 300,175,21
circle 300,175,22
circle 300,175,23
endfunction
function body()
ink rgb(0,128,128),0
line 300,194,300,275
line 301,194,301,275
line 302,194,302,275
endfunction
function rarm()
line 300,235,340,195
line 301,235,341,195
line 302,235,342,195
endfunction
function larm()
line 260,195,300,235
line 261,195,301,235
line 262,195,302,235
endfunction
function rleg()
line 300,274,335,325
line 301,274,336,325
line 302,274,336,325
endfunction
function lleg()
line 260,325,300,274
line 261,325,301,274
line 262,325,302,274
endfunction
function threeSpace()
ink rgb(192,192,192),0
line 275,450,250,450
line 275,451,250,451
line 320,450,295,450
line 320,451,295,451
line 365,450,340,450
line 365,451,340,451
endfunction
function fourSpace()
line 275,450,250,450
line 275,451,250,451
line 320,450,295,450
line 320,451,295,451
line 365,450,340,450
line 365,451,340,450
line 410,450,385,450
line 410,451,385,451
endfunction
function fiveSpace()
line 275,450,250,450
line 275,451,250,451
line 320,450,295,450
line 320,451,295,451
line 365,450,340,450
line 365,451,340,450
line 410,450,385,450
line 410,451,385,451
line 455,450,430,450
line 455,451,430,451
endfunction