Well, first of all this is my first post here so hello.
I have very little programming expirience so when I got Darkbasic I found this forum and read a lot of TDKs tuts so thanks to him for that, it helped a ton. Taking the advice on this forum I didnt start off huge and decided to do Hangman. It took my a long time with tons of trial and error but I finally got it done. Im sure my code structure and layout is an abomination and if you see anything wrong with it please tell me, especially how I can eliminate the two gotos that I use. So please tell me anything I have done wrong or anything that I can improve on it.
rem Hangman
rem Programmed By, C Grimes
rem go to the start screen
gosub startscreen
start:
rem Go to setup
gosub setup
rem put words into an array
gosub words
rem start the main game
gosub main
main:
rem choose a word randomly
y = rnd(9)+1
word$=upper$(words$(y,0))
text 350,15,"----Hint----"
if hint = 1 then text 300,50,words$(y,1)
rem seperate each letter in word$
gosub letterseperate
rem draw the lines showing how many letters are in the word
gosub lines
loop:
rem main loop
do
text 0,0," "
set cursor 0,0
rem switch
guess=0
input "Enter your guess ",guess$
if len(guess$) = 0 then goto loop:
rem make the guess upper case
guess$=upper$(guess$)
rem check if they were guessing the entire word and it is correct
if guess$ = word$
gosub finishgame
endif
rem see if the guess made matches with one of the letter
for x = 1 to lettercount
if guess$ = seperateletter$(x)
rem turn switch on
guess=1
gosub correct
exit
endif
next x
if guess=0
gosub fail
endif
loop
return
setup:
hide mouse
set text opaque
text 500,100,"--Wrong guesses--"
rem draw images
box 0,350,250,400
line 250,350,250,200
line 250,200,150,200
line 150,200,150,210
return
words:
rem dimensionalize array--word,hint
dim words$(10,10)
rem possible words:
words$(1,0)="Hello"
words$(1,1)="A greeting"
words$(2,0)="Child"
words$(2,1)="A young person"
words$(3,0)="Elder"
words$(3,1)="Someone you should respect"
words$(4,0)="Bird"
words$(4,1)="An animal that flies"
words$(5,0)="Psycho"
words$(5,1)="A crazy person"
words$(6,0)="Shark"
words$(6,1)="An ocean predator"
words$(7,0)="President"
words$(7,1)="The executive branch"
words$(8,0)="Darkbasic"
words$(8,1)="An awsome programing language"
words$(9,0)="Submarine"
words$(9,1)="A boat underwater"
words$(10,0)="Hangman"
words$(10,1)="A game"
return
letterseperate:
lettercount = len(word$)
dim seperateletter$(lettercount)
for x = 1 to lettercount
seperateletter$(x)=mid$(word$,x)
seperateletter$(x)=upper$(seperateletter$(x))
next x
return
lines:
for x = 1 to lettercount
lineposx1=lineposx1 + 40
lineposx2= lineposx1 + 30
line lineposx1 - 40,450, lineposx2 - 40,450
next x
return
correct:
gosub double
x=0
for x = x to lettercount
if guess$ = seperateletter$(x)
number = x
if exit1 = 0
exit
endif
endif
next x
exit1 = 0
if number = 1
text 10,430,guess$
endif
if number = 2
text 50,430,guess$
endif
if number = 3
text 90,430,guess$
endif
if number = 4
text 130,430,guess$
endif
if number = 5
text 170,430,guess$
endif
if number = 6
text 210,430,guess$
endif
if number = 7
text 250,430,guess$
endif
if number = 8
text 290,430,guess$
endif
if number = 9
text 330,430,guess$
endif
if double = 2
exit1 = 1
gosub correct
endif
return
double:
double = 0
for x = x to lettercount
if guess$ = seperateletter$(x) and double = 1
double = 2
endif
if guess$ = seperateletter$(x) and double = 0
double = 1
endif
next x
x=0
return
finishgame:
x=1
for x = x to len(guess$)
if x = 1
text 10,430,seperateletter$(x)
endif
if x = 2
text 50,430,seperateletter$(x)
endif
if x = 3
text 90,430,seperateletter$(x)
endif
if x = 4
text 130,430,seperateletter$(x)
endif
if x = 5
text 170,430,seperateletter$(x)
endif
if x = 6
text 210,430,seperateletter$(x)
endif
if x = 7
text 250,430,seperateletter$(x)
endif
if x = 8
text 290,430,seperateletter$(x)
endif
if x = 9
text 330,430,seperateletter$(x)
endif
next x
print "You won!"
print "Play Again? Y/N"
do
if inkey$() = "n"
end
endif
if inkey$() = "y"
gosub startscreen
endif
loop
return
startscreen:
fail=0
lineposx1=0
lineposx2=0
lettercount = 0
hints = 0
x = 0
cls
print "HANGMAN"
print
print
print
print "Play with hints(1)"
print "Play without hints(2)"
repeat
if inkey$() = "1" then hint = 1
until inkey$() = "1" or inkey$() = "2"
cls
goto start
return
fail:
yval=yval+20
text 550,100+yval,guess$
fail = fail + 1
if fail = 1
circle 150,220,10
endif
if fail = 2
line 150,230,150,280
endif
if fail = 3
line 150,280,125,310
endif
if fail = 4
line 150,280,170,310
endif
if fail = 5
line 150,250,125,250
endif
if fail = 6
line 150,250,170,250
print "You Lose Play Again? Y/N"
do
if inkey$() = "n"
end
endif
if inkey$() = "y"
gosub startscreen
endif
loop
endif
return
Again, I stumbled through this and sorry that I stopped using rem statements around half way through I started getting lazy. It isnt really a good game in the sense of fun, since there are only ten words and such but you can play it and see how it looks.