This is a remake of the first game I made on an IBM 5110 for IBM in 77-78
(Revised - Now keeps track of all time wins/losses, code was cleaned up and error handling was added)
*** To reset the wins / losses simply delete the wl.txt file
(Revised - Now keeps track of all time wins/losses, code was cleaned up and error handling was added)
*** To reset the wins / losses simply delete the wl.txt file
Code: (Select All)
$ExeIcon:'./data\hm.ico'
_Title "Hangman by David Coterel"
Screen _NewImage(662, 828, 32): x = _DesktopWidth * .5 - 331: y = _DesktopHeight * .5 - 414: _ScreenMove x, y
$Resize:Smooth
5 On Error GoTo 800
Randomize (-Timer): _Define A-Z As SINGLE
skel& = _LoadImage("data\skel.png", 32)
gp& = _LoadImage("data\gp.png", 32)
typ& = _SndOpen("data\type.wav")
BD1& = _LoadImage("data\head.png", 32)
BD2& = _LoadImage("data\larm.png", 32)
BD3& = _LoadImage("data\rarm.png", 32)
BD4& = _LoadImage("data\tors.png", 32)
BD5& = _LoadImage("data\lleg.png", 32)
BD6& = _LoadImage("data\hips.png", 32)
BD7& = _LoadImage("data\rleg.png", 32)
bm& = _SndOpen("data\dance.ogg"): _SndLoop bm&: _SndVol bm&, .15
cor& = _SndOpen("data\correct.wav"): _SndVol cor&, .5
ico& = _SndOpen("data\incorrect.wav"): _SndVol ico&, .5
win& = _SndOpen("data\win.wav"): _SndVol cor&, .5
los& = _SndOpen("data\loose.wav"): _SndVol ico&, .5
Open "data\wl.txt" For Input As #2: Input #2, wn: Input #2, ls: Close #2
Const WHITE = _RGB32(255, 255, 255)
Const PURPLE = _RGB32(112, 48, 160)
Const BLACK = _RGB32(0, 0, 0)
Const BLUE = _RGB32(0, 0, 255)
Const RED = _RGB32(255, 0, 0)
Const LGREEN = _RGB32(196, 255, 13)
Const GREEN = _RGB32(0, 255, 0)
Const orange = _RGB32(255, 195, 10)
Const brown1 = _RGB32(131, 85, 41)
Const brown2 = _RGB32(171, 125, 81)
Color BLACK, WHITE: Cls: _PutImage (140, 180), skel&: f& = _LoadFont("data\font1.ttf", 96): _Font f&
A$ = "HANGMAN": w1 = _PrintWidth(A$) * .5: Locate 1, 331 - w1: Print A$;
f& = _LoadFont("data\font2.ttf", 22): _Font f&: A$ = "By David Coterel 2025": w1 = _PrintWidth(A$) * .5
Color PURPLE: Locate 7, 331 - w1: Print A$;
f& = _LoadFont("data\font2.ttf", 32): _Font f&
A$ = "How many letters?": w1 = _PrintWidth(A$) * .5
Color PURPLE: Locate 23, 331 - w1: Print A$;
A$ = "3 4 5 6 7 8 9 10 11 12 13": w1 = _PrintWidth(A$) * .5
Color BLACK: Locate 25, 331 - w1: Print A$;
Do: m1 = _MouseInput + _MouseButton(1) + _MouseButton(2): Loop Until m1 = 0
Do: m1 = _MouseInput: m2 = _MouseX: m3 = _MouseY: m4 = _MouseButton(1): m5 = _MouseButton(2): lt = 0: y1 = 765: y2 = 797
x1 = 105: x2 = 133: If m2 > x1 And m2 < x2 And m3 > y1 And m3 < y2 Then Line (x1, y1)-(x2, y2), RED, B: lt = 3: Else Line (x1, y1)-(x2, y2), WHITE, B
x1 = 142: x2 = 170: If m2 > x1 And m2 < x2 And m3 > y1 And m3 < y2 Then Line (x1, y1)-(x2, y2), RED, B: lt = 4: Else Line (x1, y1)-(x2, y2), WHITE, B
x1 = 180: x2 = 207: If m2 > x1 And m2 < x2 And m3 > y1 And m3 < y2 Then Line (x1, y1)-(x2, y2), RED, B: lt = 5: Else Line (x1, y1)-(x2, y2), WHITE, B
x1 = 217: x2 = 243: If m2 > x1 And m2 < x2 And m3 > y1 And m3 < y2 Then Line (x1, y1)-(x2, y2), RED, B: lt = 6: Else Line (x1, y1)-(x2, y2), WHITE, B
x1 = 253: x2 = 279: If m2 > x1 And m2 < x2 And m3 > y1 And m3 < y2 Then Line (x1, y1)-(x2, y2), RED, B: lt = 7: Else Line (x1, y1)-(x2, y2), WHITE, B
x1 = 290: x2 = 316: If m2 > x1 And m2 < x2 And m3 > y1 And m3 < y2 Then Line (x1, y1)-(x2, y2), RED, B: lt = 8: Else Line (x1, y1)-(x2, y2), WHITE, B
x1 = 328: x2 = 354: If m2 > x1 And m2 < x2 And m3 > y1 And m3 < y2 Then Line (x1, y1)-(x2, y2), RED, B: lt = 9: Else Line (x1, y1)-(x2, y2), WHITE, B
x1 = 365: x2 = 405: If m2 > x1 And m2 < x2 And m3 > y1 And m3 < y2 Then Line (x1, y1)-(x2, y2), RED, B: lt = 10: Else Line (x1, y1)-(x2, y2), WHITE, B
x1 = 416: x2 = 454: If m2 > x1 And m2 < x2 And m3 > y1 And m3 < y2 Then Line (x1, y1)-(x2, y2), RED, B: lt = 11: Else Line (x1, y1)-(x2, y2), WHITE, B
x1 = 463: x2 = 501: If m2 > x1 And m2 < x2 And m3 > y1 And m3 < y2 Then Line (x1, y1)-(x2, y2), RED, B: lt = 12: Else Line (x1, y1)-(x2, y2), WHITE, B
x1 = 514: x2 = 552: If m2 > x1 And m2 < x2 And m3 > y1 And m3 < y2 Then Line (x1, y1)-(x2, y2), RED, B: lt = 13: Else Line (x1, y1)-(x2, y2), WHITE, B
Loop Until m4 = -1 And lt <> 0
Open "data/words.txt" For Input As #1: wd = 0
Do: Input #1, A$: If Len(A$) = lt Then wd = wd + 1
Loop Until EOF(1) = -1
Close #1: a = Int(Rnd(1) * wd) + 1
Open "data/words.txt" For Input As #1: wd = 0: word$ = ""
Do: Input #1, A$: If Len(A$) = lt Then wd = wd + 1: If wd = a Then word$ = A$
Loop Until EOF(1) = -1 Or word$ <> ""
Close #1
Cls: _PutImage (0, 0), gp&: GoSub 500
Color BLUE, WHITE: A$ = "A B C D E F G H I J K L M N O P Q R S T U V W X Y Z"
w1 = _PrintWidth(A$): Locate 33, 331 - (w1 * .5): Print A$;
f& = _LoadFont("data\font2.ttf", 36): _Font f&
gs$ = " ": For t = 1 To lt: g$ = g$ + "_": gs$ = gs$ + "_ ": Next t
Color BLACK: w1 = _PrintWidth(gs$): Locate 21, 331 - (w1 * .5): Print gs$;
10
Do: m1 = _MouseInput + _MouseButton(1) + _MouseButton(2): Loop Until m1 = 0
Do: m1 = _MouseInput: m2 = _MouseX: m3 = _MouseY: m4 = _MouseButton(1): m5 = _MouseButton(2): lt = 0: y1 = 768: y2 = 793
x1 = 36: x2 = 54: If m2 > x1 And m2 < x2 And m3 > y1 And m3 < y2 Then Line (x1, y1)-(x2, y2), RED, B: lt = 65: xx1 = x1: xx2 = x2: yy1 = y1: yy2 = y2: Else Line (x1, y1)-(x2, y2), WHITE, B
x1 = 61: x2 = 76: If m2 > x1 And m2 < x2 And m3 > y1 And m3 < y2 Then Line (x1, y1)-(x2, y2), RED, B: lt = 66: xx1 = x1: xx2 = x2: yy1 = y1: yy2 = y2: Else Line (x1, y1)-(x2, y2), WHITE, B
x1 = 82: x2 = 99: If m2 > x1 And m2 < x2 And m3 > y1 And m3 < y2 Then Line (x1, y1)-(x2, y2), RED, B: lt = 67: xx1 = x1: xx2 = x2: yy1 = y1: yy2 = y2: Else Line (x1, y1)-(x2, y2), WHITE, B
x1 = 105: x2 = 123: If m2 > x1 And m2 < x2 And m3 > y1 And m3 < y2 Then Line (x1, y1)-(x2, y2), RED, B: lt = 68: xx1 = x1: xx2 = x2: yy1 = y1: yy2 = y2: Else Line (x1, y1)-(x2, y2), WHITE, B
x1 = 130: x2 = 143: If m2 > x1 And m2 < x2 And m3 > y1 And m3 < y2 Then Line (x1, y1)-(x2, y2), RED, B: lt = 69: xx1 = x1: xx2 = x2: yy1 = y1: yy2 = y2: Else Line (x1, y1)-(x2, y2), WHITE, B
x1 = 150: x2 = 163: If m2 > x1 And m2 < x2 And m3 > y1 And m3 < y2 Then Line (x1, y1)-(x2, y2), RED, B: lt = 70: xx1 = x1: xx2 = x2: yy1 = y1: yy2 = y2: Else Line (x1, y1)-(x2, y2), WHITE, B
x1 = 169: x2 = 187: If m2 > x1 And m2 < x2 And m3 > y1 And m3 < y2 Then Line (x1, y1)-(x2, y2), RED, B: lt = 71: xx1 = x1: xx2 = x2: yy1 = y1: yy2 = y2: Else Line (x1, y1)-(x2, y2), WHITE, B
x1 = 194: x2 = 212: If m2 > x1 And m2 < x2 And m3 > y1 And m3 < y2 Then Line (x1, y1)-(x2, y2), RED, B: lt = 72: xx1 = x1: xx2 = x2: yy1 = y1: yy2 = y2: Else Line (x1, y1)-(x2, y2), WHITE, B
x1 = 218: x2 = 227: If m2 > x1 And m2 < x2 And m3 > y1 And m3 < y2 Then Line (x1, y1)-(x2, y2), RED, B: lt = 73: xx1 = x1: xx2 = x2: yy1 = y1: yy2 = y2: Else Line (x1, y1)-(x2, y2), WHITE, B
x1 = 231: x2 = 243: If m2 > x1 And m2 < x2 And m3 > y1 And m3 < y2 Then Line (x1, y1)-(x2, y2), RED, B: lt = 74: xx1 = x1: xx2 = x2: yy1 = y1: yy2 = y2: Else Line (x1, y1)-(x2, y2), WHITE, B
x1 = 250: x2 = 266: If m2 > x1 And m2 < x2 And m3 > y1 And m3 < y2 Then Line (x1, y1)-(x2, y2), RED, B: lt = 75: xx1 = x1: xx2 = x2: yy1 = y1: yy2 = y2: Else Line (x1, y1)-(x2, y2), WHITE, B
x1 = 273: x2 = 286: If m2 > x1 And m2 < x2 And m3 > y1 And m3 < y2 Then Line (x1, y1)-(x2, y2), RED, B: lt = 76: xx1 = x1: xx2 = x2: yy1 = y1: yy2 = y2: Else Line (x1, y1)-(x2, y2), WHITE, B
x1 = 293: x2 = 315: If m2 > x1 And m2 < x2 And m3 > y1 And m3 < y2 Then Line (x1, y1)-(x2, y2), RED, B: lt = 77: xx1 = x1: xx2 = x2: yy1 = y1: yy2 = y2: Else Line (x1, y1)-(x2, y2), WHITE, B
x1 = 323: x2 = 341: If m2 > x1 And m2 < x2 And m3 > y1 And m3 < y2 Then Line (x1, y1)-(x2, y2), RED, B: lt = 78: xx1 = x1: xx2 = x2: yy1 = y1: yy2 = y2: Else Line (x1, y1)-(x2, y2), WHITE, B
x1 = 348: x2 = 367: If m2 > x1 And m2 < x2 And m3 > y1 And m3 < y2 Then Line (x1, y1)-(x2, y2), RED, B: lt = 79: xx1 = x1: xx2 = x2: yy1 = y1: yy2 = y2: Else Line (x1, y1)-(x2, y2), WHITE, B
x1 = 374: x2 = 389: If m2 > x1 And m2 < x2 And m3 > y1 And m3 < y2 Then Line (x1, y1)-(x2, y2), RED, B: lt = 80: xx1 = x1: xx2 = x2: yy1 = y1: yy2 = y2: Else Line (x1, y1)-(x2, y2), WHITE, B
x1 = 395: x2 = 414: If m2 > x1 And m2 < x2 And m3 > y1 And m3 < y2 Then Line (x1, y1)-(x2, y2), RED, B: lt = 81: xx1 = x1: xx2 = x2: yy1 = y1: yy2 = y2: Else Line (x1, y1)-(x2, y2), WHITE, B
x1 = 421: x2 = 437: If m2 > x1 And m2 < x2 And m3 > y1 And m3 < y2 Then Line (x1, y1)-(x2, y2), RED, B: lt = 82: xx1 = x1: xx2 = x2: yy1 = y1: yy2 = y2: Else Line (x1, y1)-(x2, y2), WHITE, B
x1 = 443: x2 = 458: If m2 > x1 And m2 < x2 And m3 > y1 And m3 < y2 Then Line (x1, y1)-(x2, y2), RED, B: lt = 83: xx1 = x1: xx2 = x2: yy1 = y1: yy2 = y2: Else Line (x1, y1)-(x2, y2), WHITE, B
x1 = 463: x2 = 481: If m2 > x1 And m2 < x2 And m3 > y1 And m3 < y2 Then Line (x1, y1)-(x2, y2), RED, B: lt = 84: xx1 = x1: xx2 = x2: yy1 = y1: yy2 = y2: Else Line (x1, y1)-(x2, y2), WHITE, B
x1 = 487: x2 = 504: If m2 > x1 And m2 < x2 And m3 > y1 And m3 < y2 Then Line (x1, y1)-(x2, y2), RED, B: lt = 85: xx1 = x1: xx2 = x2: yy1 = y1: yy2 = y2: Else Line (x1, y1)-(x2, y2), WHITE, B
x1 = 510: x2 = 528: If m2 > x1 And m2 < x2 And m3 > y1 And m3 < y2 Then Line (x1, y1)-(x2, y2), RED, B: lt = 86: xx1 = x1: xx2 = x2: yy1 = y1: yy2 = y2: Else Line (x1, y1)-(x2, y2), WHITE, B
x1 = 534: x2 = 560: If m2 > x1 And m2 < x2 And m3 > y1 And m3 < y2 Then Line (x1, y1)-(x2, y2), RED, B: lt = 87: xx1 = x1: xx2 = x2: yy1 = y1: yy2 = y2: Else Line (x1, y1)-(x2, y2), WHITE, B
x1 = 565: x2 = 582: If m2 > x1 And m2 < x2 And m3 > y1 And m3 < y2 Then Line (x1, y1)-(x2, y2), RED, B: lt = 88: xx1 = x1: xx2 = x2: yy1 = y1: yy2 = y2: Else Line (x1, y1)-(x2, y2), WHITE, B
x1 = 588: x2 = 604: If m2 > x1 And m2 < x2 And m3 > y1 And m3 < y2 Then Line (x1, y1)-(x2, y2), RED, B: lt = 89: xx1 = x1: xx2 = x2: yy1 = y1: yy2 = y2: Else Line (x1, y1)-(x2, y2), WHITE, B
x1 = 610: x2 = 626: If m2 > x1 And m2 < x2 And m3 > y1 And m3 < y2 Then Line (x1, y1)-(x2, y2), RED, B: lt = 90: xx1 = x1: xx2 = x2: yy1 = y1: yy2 = y2: Else Line (x1, y1)-(x2, y2), WHITE, B
Loop Until m4 = -1 And lt <> 0
w = 0: For t = 1 To Len(word$)
If Mid$(g$, t, 1) = "_" And UCase$(Mid$(word$, t, 1)) = Chr$(lt) Then Mid$(g$, t, 1) = Chr$(lt): w = 1: _SndPlay cor&
Next t: If w = 0 And InStr(us$, Chr$(lt)) = 0 Then p = p + 1: GoSub 100: If p = 7 Then GoTo 200
gs$ = " ": us$ = us$ + Chr$(lt): For t = 1 To Len(word$)
gs$ = gs$ + Mid$(g$, t, 1) + " ": Next t: w1 = _PrintWidth(gs$)
Locate 21, 331 - (w1 * .5): Print gs$;: Line (xx1, yy1)-(xx2, yy2), WHITE, BF
If UCase$(word$) = UCase$(g$) Then 400
GoTo 10
100 'Put body parts on screen
_SndPlay ico&
If p = 1 Then _PutImage (352, 130), BD1&
If p = 3 Then _PutImage (200, 230), BD2&
If p = 4 Then _PutImage (480, 252), BD3&
If p = 2 Then _PutImage (355, 265), BD4&
If p = 5 Then _PutImage (350, 380), BD6&
If p = 6 Then _PutImage (320, 440), BD5&
If p = 7 Then _PutImage (440, 430), BD7&
Return
200 'Lose
ls = ls + 1: GoSub 500
Line (200, 130)-(662, 585), WHITE, BF: Line (260, 585)-(662, 630), WHITE, BF: _SndPlay los&
For t = 1 To 60: _Limit 45: _PutImage (245, 124 + t), skel&: Line (423, 120)-(437, 123 + t), orange, BF: Next t
For t = 59 To 1 Step -1: _Limit 95: _PutImage (245, 124 + t), skel&: Next t
For t = 1 To 60: _Limit 145: _PutImage (245, 124 + t), skel&: Line (423, 120)-(437, 123 + t), orange, BF: Next t
Color RED, WHITE: Locate 28, 390: Print "Sorry you loose..."
Color BLACK: Locate 29, 390: Print "Play again [LM/RM]": A$ = "The Word Was: " + UCase$(word$): w1 = _PrintWidth(A$) * .5
Locate 3, 331 - w1: Color LGREEN, BLACK: Print A$;
300 'Quit or play agin
Open "data\wl.txt" For Output As #2: Print #2, wn: Print #2, ls: Close #2
Do: m1 = _MouseInput + _MouseButton(1) + _MouseButton(2): Loop Until m1 = 0
Do: m1 = _MouseInput: m4 = _MouseButton(1): m5 = _MouseButton(2)
Loop Until m4 = -1 Or m5 = -1: If m4 = -1 Then _SndStop bm&: Clear: GoTo 5
System
400 'Winner
Line (200, 130)-(662, 585), WHITE, BF: Line (260, 585)-(662, 630), WHITE, BF: _SndPlay win&
_PutImage (0, 0), gp&: _PutImage (315, 270)-(499, 620), skel&: wn = wn + 1: GoSub 500
Color GREEN, WHITE: Locate 28, 390: Print "YOU WON!!!!"
Color BLACK: Locate 29, 390: Print "Play again [LM/RM]": A$ = "WINNER WINNER WINNER": w1 = _PrintWidth(A$) * .5
Locate 3, 331 - w1: Color LGREEN, BLACK: Print A$;
For t = 1 To 100: _Limit 45: _PutImage (315 + t, 270)-(499 + t, 620), skel&: Next t
For t = 99 To -70 Step -1: _Limit 95: _PutImage (315 + t, 270)-(499 + t, 620), skel&: Next t
For t = -69 To 347: _Limit 145: _PutImage (315 + t, 270)-(499 + t, 620), skel&: Next t
GoTo 300
500 'Print stats on tree
Color brown1, brown2: f& = _LoadFont("data\font2.ttf", 24): _Font f&
A$ = "Wins": w1 = _PrintWidth(A$) * .5: Locate 16, 98 - w1: Print A$;
A$ = Str$(wn): A$ = Right$(A$, Len(A$) - 1): w1 = _PrintWidth(A$) * .5: Locate 17, 98 - w1: Print A$;
A$ = "Losses": w1 = _PrintWidth(A$) * .5: Locate 18, 98 - w1: Print A$;
A$ = Str$(ls): A$ = Right$(A$, Len(A$) - 1): w1 = _PrintWidth(A$) * .5: Locate 19, 98 - w1: Print A$;
Return
800 'Error Handling
If Err = 53 And _ErrorLine = 25 Then Open "data\wl.txt" For Output As #2: Print #2, 0: Print #2, 0: Close #2: Clear: GoTo 5
Cls
If Err = 53 And _ErrorLine = 65 Then Cls: Print "The words file is either corrupted or": Print "missing, the system will be halted!"
Print "An error has ocurred:": Print "Error#:"; Err: Print "In Line#:"; _ErrorLine
Print "The system will be halted!": End

