~hangman8086-devs/hangman8086/trunk

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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;      __   __  _______  __    _  _______  __   __  _______  __    _       ;;
;;     |  | |  ||   _   ||  |  | ||       ||  |_|  ||   _   ||  |  | |      ;;
;;     |  |_|  ||  |_|  ||   |_| ||    ___||       ||  |_|  ||   |_| |      ;;
;;     |       ||       ||       ||   | __ |       ||       ||       |      ;;
;;     |       ||       ||  _    ||   ||  ||       ||       ||  _    |      ;;
;;     |   _   ||   _   || | |   ||   |_| || ||_|| ||   _   || | |   |      ;;
;;     |__| |__||__| |__||_|  |__||_______||_|   |_||__| |__||_|  |__|      ;;
;;                                                                          ;;
;;                                                                          ;;
;;  HANGMAN - An implementation of the Hang Man game in assembly (Emu8086)  ;;
;;                                                                          ;;
;;  Copyright (C) 2011  Fabien LOISON                                       ;;
;;  Copyright (C) 2011  Mathilde BOUTIGNY                                   ;;
;;  Copyright (C) 2011  Vincent PEYROUSE                                    ;;
;;  Copyright (C) 2011  Germain CARRÉ                                       ;;
;;  Copyright (C) 2011  Matthis FRENAY                                      ;;
;;                                                                          ;;
;;  HangMan is free software: you can redistribute it and/or modify         ;;
;;  it under the terms of the GNU General Public License as published by    ;;
;;  the Free Software Foundation, either version 3 of the License, or       ;;
;;  (at your option) any later version.                                     ;;
;;                                                                          ;;
;;  This program is distributed in the hope that it will be useful,         ;;
;;  but WITHOUT ANY WARRANTY; without even the implied warranty of          ;;
;;  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           ;;
;;  GNU General Public License for more details.                            ;;
;;                                                                          ;;
;;  You should have received a copy of the GNU General Public License       ;;
;;  along with this program.  If not, see <http://www.gnu.org/licenses/>.   ;;
;;                                                                          ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;
;; Contains the two players mode.
;;
;; Index:
;;     _two_players()            -- Play in two players mode.
;;



;======================================================= _two_players() ====
;; Play in two players mode.

;; Usage:
;; call _two_players


_two_players:

;Backup registers

push ax
push bx
push cx
push dx

;Get the mode

call _mode_menu

;Back to the main menu if necessary
cmp MODE, -1
je tp_end


;Ask the first player's name
mov IF_MSG, offset tp_msg_fplname
mov IF_MAXLEN, 8
mov IF_EWD, 0
call _input_field
mov MEMCPY_SRC, offset IF_WORD
mov MEMCPY_DEST, offset tp_fplname
mov MEMCPY_LEN, 8
call _memcpy
nop

;Ask the second player's name

mov IF_MSG, offset tp_msg_splname
mov IF_MAXLEN, 8
mov IF_EWD, 0
call _input_field
mov MEMCPY_SRC, offset IF_WORD
mov MEMCPY_DEST, offset tp_splname
mov MEMCPY_LEN, 8
call _memcpy
nop



;Game loop.

mov cx, 3
tp_game_loop:

;Ask the first player's secret word.

mov MEMCPY_SRC, offset tp_fplname
mov MEMCPY_DEST, offset tp_msg_fplword
mov MEMCPY_LEN, 8
call _memcpy
mov IF_MSG, offset tp_msg_fplword
mov IF_MAXLEN, 26
mov IF_EWD, 1
call _input_field
mov MEMCPY_SRC, offset IF_WORD
mov MEMCPY_DEST, offset tp_fplword
mov MEMCPY_LEN, 26
call _memcpy
nop

;Let's play with the second player !

mov WORD, offset tp_fplword
;SET PLAYER
mov MEMCPY_SRC, offset tp_splname
mov MEMCPY_DEST, offset PLAYER
mov MEMCPY_LEN, 8
call _memcpy

;SET SCORE
mov ah, 0
mov al, play_sp_lives
mov SCORE, ax

call _play


;Count the second player's lives.

mov ax, 0
mov al, play_lives
add play_sp_lives, al

;Test if play whith gibbets, add 6 points if yes.
cmp OPTION_GIBBET, OPTION_GIBBET_ON
jnz tp_gibbet_end_sp:
add play_sp_lives, 6
tp_gibbet_end_sp:

;Abort game.

cmp GAME_STATUS, GAME_STATUS_ABORT
je tp_end

;Ask the second player's secret word.

mov MEMCPY_SRC, offset tp_splname
mov MEMCPY_DEST, offset tp_msg_splword
mov MEMCPY_LEN, 8
call _memcpy
mov IF_MSG, offset tp_msg_splword
mov IF_MAXLEN, 26
mov IF_EWD, 1
call _input_field
mov MEMCPY_SRC, offset IF_WORD
mov MEMCPY_DEST, offset tp_splword
mov MEMCPY_LEN, 26
call _memcpy
nop

;Let's play with the first player !

mov WORD, offset tp_splword
;SET PLAYER
mov MEMCPY_SRC, offset tp_fplname
mov MEMCPY_DEST, offset PLAYER
mov MEMCPY_LEN, 8
call _memcpy

;SET SCORE
mov ah, 0
mov al, play_fp_lives
mov SCORE, ax

call _play

;Count the first player's lives.

mov ax, 0
mov al, play_lives
add play_fp_lives, al

;Test if play whith gibbets, add 6 points if yes.
cmp OPTION_GIBBET, OPTION_GIBBET_ON
jnz tp_gibbet_end2:
add play_fp_lives, 6
tp_gibbet_end2:

;Abort game.

cmp GAME_STATUS, GAME_STATUS_ABORT
je tp_end

;Game loop.

dec cx
cmp cx, 0
jne tp_game_loop

;Put the number of lives of the second player in ax.

mov ax, 0
mov al, play_sp_lives

;Jump to fp_win if the first player win.

call _draw_ui

cmp play_fp_lives, al
jg fp_win

;Display message if second player win.

;check if competition mode is set.
cmp MODE, MODE_COMPETITION
jne norm_sp_win

;SCORE
mov NTPS_NAME, offset tp_splname
mov ah, 0
mov al, play_sp_lives
mov NTPS_SCORE, ax
call _new_tp_score

norm_sp_win:
mov POS_X, (COLS-24)/2
mov POS_Y, header_height + 4
call _move_cursor
mov MEMCPY_SRC, offset tp_splname
mov MEMCPY_DEST, offset tp_msg_win
mov MEMCPY_LEN, 8
call _memcpy
mov ah, 0x09
mov dx, offset tp_msg_win
int 0x21

cmp MODE, MODE_COMPETITION
jnz norm_sp_win_end

add POS_Y, 2
call _move_cursor

mov ah, 0
mov al, play_sp_lives
mov I2S_INT, ax
call _inttostr

mov MEMCPY_SRC, offset I2S_STR
mov MEMCPY_DEST, offset tp_msg_score
add MEMCPY_DEST, 7
mov MEMCPY_LEN, 4
call _memcpy

mov ah, 0x09
mov dx, offset tp_msg_score
int 0x21

norm_sp_win_end:

;wait
mov ah, 0x86
mov cx, 96
int 0x15

jmp tp_end

;Display message if first player win.

fp_win:

;Check if competition mode is set.
cmp MODE, MODE_COMPETITION
jne norm_fp_win

;SCORE
mov NTPS_NAME, offset tp_fplname
mov ah, 0
mov al, play_sp_lives
mov NTPS_SCORE, ax
call _new_tp_score

norm_fp_win:
mov POS_X, (COLS-24)/2
mov POS_Y, header_height + 4
call _move_cursor
mov MEMCPY_SRC, offset tp_fplname
mov MEMCPY_DEST, offset tp_msg_win
mov MEMCPY_LEN, 8
call _memcpy
mov ah, 0x09
mov dx, offset tp_msg_win
int 0x21

cmp MODE, MODE_COMPETITION
jnz norm_fp_win_end

add POS_Y, 2
call _move_cursor

mov ah, 0
mov al, play_fp_lives
mov I2S_INT, ax
call _inttostr

mov MEMCPY_SRC, offset I2S_STR
mov MEMCPY_DEST, offset tp_msg_score
add MEMCPY_DEST, 7
mov MEMCPY_LEN, 4
call _memcpy

mov ah, 0x09
mov dx, offset tp_msg_score
int 0x21

norm_fp_win_end:

;wait
mov ah, 0x86
mov cx, 96
int 0x15

tp_end:

;Restore registers

pop dx
pop cx
pop bx
pop ax


ret


;Datas

tp_msg_fplname db "Please enter the first player's name:$"
tp_fplname db "--------"
tp_msg_splname db "Please enter the second player's name:$"
tp_splname db "--------"

tp_msg_fplword db "******** enter your secret word:$"
tp_fplword db "-------------------------"
tp_msg_splword db "******** enter your secret word:$"
tp_splword db "-------------------------"

tp_msg_win db "******** is the winner !$"

tp_msg_score db "Score: 0000$"

play_fp_lives db 0
play_sp_lives db 0