-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsnake.asm
200 lines (166 loc) · 3.16 KB
/
snake.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
.386
.model flat, stdcall
.stack 4096
ExitProcess PROTO, dwExitCode: DWORD
INCLUDE Irvine32.inc
.data
xWall BYTE 52 DUP("#"), 0
strScore BYTE "Skor: ", 0
score BYTE 0
strTryAgain BYTE "Tekrar Dene? 1=evet, 0=hayir", 0
invalidInput BYTE "Geçersiz giriş", 0
strYouDied BYTE "Geberdin kanka ", 0
strPoints BYTE " puan", 0
blank BYTE " ", 0
snake BYTE "X", 104 DUP("x")
xPos BYTE 45,44,43,42,41, 100 DUP(?)
yPos BYTE 15,15,15,15,15, 100 DUP(?)
xPosWall BYTE 34,34,85,85
yPosWall BYTE 5,24,5,24
xCoinPos BYTE ?
yCoinPos BYTE ?
inputChar BYTE "+"
lastInputChar BYTE ?
strSpeed BYTE "Hız (1-hızlı, 2-orta, 3-yavaş): ", 0
speed DWORD 0
.code
main PROC
call DrawWall
call DrawScoreboard
call ChooseSpeed
mov esi, 0
mov ecx, 5
drawSnake:
call DrawPlayer
inc esi
loop drawSnake
call Randomize
call CreateRandomCoin
call DrawCoin
gameLoop::
mov dl, 106
mov dh, 1
call Gotoxy
call ReadKey
jz noKey
mov bl, inputChar
mov lastInputChar, bl
mov inputChar, al
noKey:
cmp inputChar, "x"
je exitgame
cmp inputChar, "w"
je checkTop
cmp inputChar, "s"
je checkBottom
cmp inputChar, "a"
je checkLeft
cmp inputChar, "d"
je checkRight
jne gameLoop
; Hareket kontrolleri ve ölü kontrolü
checkBottom:
cmp lastInputChar, "w"
je dontChgDirection
mov cl, yPosWall[1]
dec cl
cmp yPos[0], cl
jl moveDown
je died
checkLeft:
cmp lastInputChar, "+"
je dontGoLeft
cmp lastInputChar, "d"
je dontChgDirection
mov cl, xPosWall[0]
inc cl
cmp xPos[0], cl
jg moveLeft
je died
checkRight:
cmp lastInputChar, "a"
je dontChgDirection
mov cl, xPosWall[2]
dec cl
cmp xPos[0], cl
jl moveRight
je died
checkTop:
cmp lastInputChar, "s"
je dontChgDirection
mov cl, yPosWall[0]
inc cl
cmp yPos, cl
jg moveUp
je died
; Yukarı hareket
moveUp:
mov eax, speed
add eax, speed
call delay
mov esi, 0
call UpdatePlayer
dec yPos[esi]
call DrawPlayer
call DrawBody
call CheckSnake
jmp gameLoop
; Aşağı hareket
moveDown:
mov eax, speed
add eax, speed
call delay
mov esi, 0
call UpdatePlayer
inc yPos[esi]
call DrawPlayer
call DrawBody
call CheckSnake
jmp gameLoop
; Sol hareket
moveLeft:
mov eax, speed
call delay
mov esi, 0
call UpdatePlayer
dec xPos[esi]
call DrawPlayer
call DrawBody
call CheckSnake
jmp gameLoop
; Sağ hareket
moveRight:
mov eax, speed
call delay
mov esi, 0
call UpdatePlayer
inc xPos[esi]
call DrawPlayer
call DrawBody
call CheckSnake
jmp gameLoop
checkcoin::
mov esi, 0
mov bl, xPos[0]
cmp bl, xCoinPos
jne gameLoop
mov bl, yPos[0]
cmp bl, yCoinPos
jne gameLoop
call EatingCoin
jmp gameLoop
dontChgDirection:
mov inputChar, bl
jmp noKey
dontGoLeft:
mov inputChar, "+"
jmp gameLoop
; Oyun bittiğinde
died::
call YouDied
call ReinitializeGame
jmp main
exitgame::
INVOKE ExitProcess, 0
main ENDP
; Diğer fonksiyonlar burada