Rev 1020 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
950 | leency | 1 | use32 |
2 | org 0x0 |
||
3 | db 'MENUET01' |
||
4 | dd 0x01 |
||
5 | dd _preSTART |
||
6 | dd I_END |
||
7 | dd 0x4000 |
||
8 | dd 0x4000 |
||
9 | dd 0x0,0x0 |
||
10 | |||
5093 | clevermous | 11 | include '../../macros.inc' |
950 | leency | 12 | include 'lang.inc' |
13 | include 'draw_window.inc' |
||
14 | include 'ball_operations.inc' |
||
15 | include 'basic_alg.inc' |
||
16 | |||
17 | _preSTART: |
||
18 | mcall 66, 1, 1 ;принимаем скан-коды |
||
19 | mcall 3 ;randomize |
||
20 | ror eax, 16 |
||
21 | mov [TC_U_SYSTEM_RANDSEED], eax ;from PPro "system.inc" |
||
22 | |||
23 | new_game: |
||
24 | ;обнуление матрицы |
||
25 | mov eax, 0 |
||
26 | mov ecx, 81 / 4 |
||
27 | mov edi, lineBall |
||
28 | rep stosd |
||
29 | stosb |
||
30 | |||
31 | mov [score], 0 |
||
32 | mov [countAllBall], 0 |
||
33 | mov [current], 0 |
||
34 | @@: |
||
35 | mov ebx, 7 |
||
36 | call random |
||
37 | inc dl |
||
38 | call add_new_ball |
||
1020 | diamond | 39 | call test_new_ball |
40 | cmp [countAllBall], 5 |
||
41 | jb @b |
||
950 | leency | 42 | call generate_new___new_color |
43 | |||
44 | START: |
||
45 | draw_window |
||
46 | still: |
||
47 | mcall 10 |
||
48 | |||
49 | dec eax |
||
50 | jz START ; перерисовать окно |
||
51 | dec eax |
||
52 | jnz button ;если не клавиша - значит кнопка |
||
53 | |||
54 | key: ; нажатие клавиши |
||
55 | mcall 2 ; получаем код клавиши |
||
56 | cmp ah, 60 |
||
57 | je new_game |
||
58 | jmp still |
||
59 | |||
60 | button: ; нажатие кнопки |
||
61 | mcall 17 |
||
62 | shr eax, 8 |
||
63 | cmp ax, 1 ; если кнопка выхода? |
||
64 | je .exit |
||
65 | |||
66 | ;проверим, не пуста ли клетка |
||
67 | mov edx, [current] |
||
68 | test byte [eax + lineBall - 2], 0x7 |
||
69 | jz .blank |
||
70 | |||
71 | ;проверим не была ли эта клетка уже выбрана |
||
72 | cmp eax, edx |
||
73 | je .double_choice |
||
74 | |||
75 | mov [current], eax |
||
76 | call choice_ball |
||
77 | call paint_ball ;сначала прорисуем новый выбранный шарик |
||
78 | |||
79 | test edx, edx ;cmp [current], 0 |
||
80 | jz still |
||
81 | mov eax, edx |
||
82 | |||
83 | @@: |
||
84 | call redraw_cell ;а уже потом уберем рамку от старого |
||
85 | call paint_ball |
||
86 | jmp still |
||
87 | |||
88 | .double_choice: |
||
89 | mov [current], 0 |
||
90 | jmp @B |
||
91 | |||
92 | .blank: ;нажатая кнопка - пуста |
||
93 | test edx, edx ;cmp [current], 0 |
||
94 | jz still |
||
95 | mov [dest], eax ;кнопку назначения -> в [dest] |
||
96 | mov eax, edx ;параметр в eax |
||
97 | call test_path ;вызываем рекурсию test_path |
||
98 | call zero_cheked |
||
99 | jnc still |
||
100 | |||
101 | ;^^^^^^^^^^^^^^^^^ move_ball proc |
||
102 | mov eax, [current] |
||
103 | mov cl, byte [eax + lineBall - 2] |
||
104 | mov byte [eax + lineBall - 2], 0 |
||
105 | mov eax, [dest] |
||
106 | mov byte [eax + lineBall - 2], cl |
||
107 | |||
108 | mov eax, [current] |
||
109 | call redraw_cell |
||
110 | mov eax, [dest] |
||
111 | call paint_ball |
||
112 | mov [current], 0 |
||
113 | ;^^^^^^^^^^^^^^^^^ move_ball endp |
||
114 | |||
115 | call find_line |
||
116 | call vanish_balls |
||
117 | call zero_cheked |
||
118 | |||
119 | cmp [countVanishBall], 0 |
||
120 | je new_3_balls |
||
121 | movzx eax, [countVanishBall] |
||
122 | inc eax |
||
123 | add [score], eax |
||
124 | sub [countAllBall], al |
||
125 | call redraw_score |
||
126 | jmp still |
||
127 | |||
128 | .exit: |
||
129 | mcall -1 ;выходим |
||
130 | |||
131 | new_3_balls: |
||
132 | |||
133 | rept 3 num |
||
134 | { |
||
135 | mov dl, [newColor#num] |
||
136 | call add_new_ball |
||
137 | call test_new_ball |
||
138 | cmp [countAllBall],81 |
||
139 | je .record_li |
||
140 | } |
||
141 | |||
142 | call generate_new___new_color |
||
143 | call paint_new_color |
||
144 | jmp still |
||
145 | |||
146 | .record_li: |
||
147 | mov eax, [score] |
||
148 | cmp eax, [record] |
||
149 | jbe still |
||
150 | mov [record], eax |
||
151 | jmp START |
||
152 | |||
153 | zero_cheked: ;обнуление матрицы cheked |
||
154 | pushfd |
||
155 | mov eax, lineBall |
||
156 | mov ecx, 81 |
||
157 | @@: |
||
158 | and byte [eax], 0x7 |
||
159 | inc eax |
||
160 | loop @B |
||
161 | popfd |
||
162 | ret |
||
163 | |||
164 | random: ; edx := random [0..(ebx-1)] |
||
165 | mov eax, 134775813 |
||
166 | mul [TC_U_SYSTEM_RANDSEED] |
||
167 | inc eax |
||
168 | mov [ TC_U_SYSTEM_RANDSEED], eax |
||
169 | xor edx, edx |
||
170 | div ebx |
||
171 | ret |
||
172 | |||
173 | generate_new___new_color: |
||
174 | rept 3 num |
||
175 | { |
||
176 | mov ebx, 7 |
||
177 | call random |
||
178 | inc dl |
||
179 | mov [newColor#num], dl |
||
180 | } |
||
181 | ret |
||
182 | |||
183 | add_new_ball: ;в dl - цвет шарика |
||
184 | mov ebp, edx |
||
185 | mov ebx, 81 |
||
186 | sub bl, [countAllBall] |
||
187 | call random |
||
188 | mov ecx, edx |
||
189 | mov eax, lineBall-1 |
||
190 | inc ecx |
||
191 | @@: |
||
192 | inc eax |
||
193 | test byte [eax], 0x7 |
||
194 | jnz @B |
||
195 | loop @B |
||
196 | |||
197 | ;теперь у нас в eax - адрес нашего шарика |
||
198 | mov edx, ebp |
||
199 | or byte [eax], dl |
||
200 | inc [countAllBall] |
||
1020 | diamond | 201 | ;получим ID кнопки |
202 | sub eax, lineBall-2 |
||
203 | mov [dest], eax |
||
950 | leency | 204 | ret |
205 | |||
206 | test_new_ball: |
||
207 | call paint_ball |
||
208 | |||
209 | call find_line |
||
210 | call vanish_balls |
||
211 | call zero_cheked |
||
212 | |||
213 | cmp [countVanishBall], 0 |
||
214 | je @F |
||
215 | movzx eax, [countVanishBall] |
||
216 | inc eax |
||
217 | add [score], eax |
||
218 | sub [countAllBall], al |
||
219 | call redraw_score |
||
220 | @@: |
||
221 | ret |
||
222 | |||
223 | if lang eq ru |
||
1020 | diamond | 224 | szTitle db 'Цветные линии v 0.3',0 |
950 | leency | 225 | szNewGame db 'F2 - новая игра',0 |
226 | szRecord db 'Рекорд',0 |
||
227 | szScore db 'Очки',0 |
||
228 | else |
||
1020 | diamond | 229 | szTitle db 'Color lines v 0.3',0 |
950 | leency | 230 | szNewGame db 'F2 - new game',0 |
231 | szRecord db 'Record',0 |
||
232 | szScore db 'Score',0 |
||
233 | end if |
||
234 | |||
235 | |||
236 | blank = 0xB8C2D3 |
||
237 | brown = 0x804000 |
||
238 | red = 0xff0000 |
||
239 | yellow = 0xffff00 |
||
240 | green = 0x008000 |
||
241 | cyan = 0x00ffff |
||
242 | blue = 0x0000ff |
||
243 | purple = 0x800080 |
||
244 | |||
245 | tableColor dd blank,brown,red,yellow,green,cyan,blue,purple |
||
246 | |||
247 | lineCoord: |
||
248 | rept 9 coory:0 |
||
249 | { |
||
250 | rept 9 coorx:0 |
||
251 | \{ |
||
252 | dw coorx*256+coory |
||
253 | |||
254 | \} |
||
255 | } |
||
256 | |||
257 | record dd 25 |
||
258 | |||
259 | lineBall db 81 dup ? |
||
260 | score dd ? |
||
261 | baseAddr dd ? |
||
262 | current dd ? |
||
263 | dest dd ? |
||
264 | |||
265 | newColor1 db ? |
||
266 | newColor2 db ? |
||
267 | newColor3 db ? |
||
268 | |||
269 | countVanishBall db ? |
||
270 | countAllBall db ? |
||
271 | |||
272 | TC_U_SYSTEM_RANDSEED dd ? |
||
273 | bitID dd ? |
||
274 | |||
275 | I_END: |