-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.asm
99 lines (96 loc) · 2.35 KB
/
main.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
.386
.model flat,stdcall
.stack 4096
ExitProcess PROTO, dwExitCode:DWORD
INCLUDE irvine32.inc
INCLUDE logic.inc
INCLUDE graphics.inc
INCLUDE colors.inc
.data
wod DWORD ?
bufferWord BYTE 7 DUP (?), 0
tries BYTE 0
square_length BYTE 50
square_height BYTE 15
try_again BYTE "Play again? [y/n] ",0
.code
main PROC PUBLIC
; start by getting random word
call Randomize
GameOn:
call SelectRandomWord
mov wod, edx
mov tries, 0
; setting display
call SetDisplay
LoopRows:
mov dh, square_height
add dh, tries
mov dl, square_length
call GotoXY ; dont need to set position because theyre already set
; getting word input
mov ecx, 7
mov edx, OFFSET bufferWord
mov eax, (tableBackground * 16) + fontColor
call SetTextColor
call ReadString
; checking that inputed string is correct size
cmp eax, 5
jne Error
; checking that word is in dictionary
push OFFSET bufferWord
call isWord
jne Error
jmp LoopNoError
Error:
; display line too short
movzx ebx, tries
push ebx
call ClearLine
call DisplayError
jmp DoLoopRows
DoLoopRows:
loop LoopRows
LoopNoError:
; moving cursor back to beginning of line
mov dh, square_height
add dh, tries
mov dl, square_length
call GotoXY ; dont need to set position because theyre already set
push wod
push OFFSET bufferWord
call CheckWord
push wod
push OFFSET bufferWord
call Str_compare
je DisplayWinner
inc tries
cmp tries, 6
je DisplayLoser
; move cursor down 1 row
jmp DoLoopRows
; gone through tries, you have lost
DisplayLoser:
push wod
call Loser
jmp Stop
DisplayWinner:
; looks like theyve won. Time to show it
call Winner
Stop:
mov dl, 25
mov dh, 25
call GotoXY
mov eax, fontColor
call SetTextColor
mov edx, OFFSET try_again
call WriteString
TryAgainPrompt:
call ReadChar
cmp al, 'y'
je GameOn
cmp al, 'n'
jne TryAgainPrompt
INVOKE ExitProcess, 0
main ENDP
END main