1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;; __ __ _______ __ _ _______ __ __ _______ __ _ ;;
3
;; | | | || _ || | | || || |_| || _ || | | | ;;
4
;; | |_| || |_| || |_| || ___|| || |_| || |_| | ;;
5
;; | || || || | __ | || || | ;;
6
;; | || || _ || || || || || _ | ;;
7
;; | _ || _ || | | || |_| || ||_|| || _ || | | | ;;
8
;; |__| |__||__| |__||_| |__||_______||_| |_||__| |__||_| |__| ;;
11
;; HANGMAN - An implementation of the Hang Man game in assembly (Emu8086) ;;
13
;; Copyright (C) 2011 Fabien LOISON ;;
14
;; Copyright (C) 2011 Mathilde BOUTIGNY ;;
15
;; Copyright (C) 2011 Vincent PEYROUSE ;;
16
;; Copyright (C) 2011 Germain CARR� ;;
17
;; Copyright (C) 2011 Matthis FRENAY ;;
19
;; HangMan is free software: you can redistribute it and/or modify ;;
20
;; it under the terms of the GNU General Public License as published by ;;
21
;; the Free Software Foundation, either version 3 of the License, or ;;
22
;; (at your option) any later version. ;;
24
;; This program is distributed in the hope that it will be useful, ;;
25
;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;;
26
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;;
27
;; GNU General Public License for more details. ;;
29
;; You should have received a copy of the GNU General Public License ;;
30
;; along with this program. If not, see <http://www.gnu.org/licenses/>. ;;
32
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
36
;; Contains the game functions.
39
;; _play(WORD) -- Play to hangman.
40
;; _game_init() -- Initializes the game.
41
;; _print_gibbet() -- Prints the gibbet with remaining lives.
42
;; _print_gword() -- Prints the guessed word (e.g. H _ _ _ _ _ N).
43
;; _print_tried_letters -- Prints the letters that the player have already
44
;; tried (e.g. A U I O W).
45
;; _game_anima() -- Displays an animation when the player loose
51
GAME_STATUS_LOOSE equ 0
53
GAME_STATUS_ABORT equ 2
57
;============================================================ _play(WORD) ====
61
;; mov WORD, offset <word>
65
WORD dw 0 ;The adress of the word to guess.
68
GAME_STATUS db 0 ;The game status (GAME_STATUS_LOOSE, GAME_STATUS_WIN,
81
mov HELP_STR, offset game_help
85
mov GAME_STATUS, GAME_STATUS_LOOSE
91
call _print_tried_letters
94
;Check if the play win
95
;For checking we search underscores in play_gword... It is not very
96
;pretty but it works...
99
mov bx, offset play_gword
102
je play_check_win_end ;not won yet
106
jne play_check_win_loop
108
mov GAME_STATUS, GAME_STATUS_WIN
115
;Check fo special keys
116
cmp LETTER, KB_ENTER ;skip Enter
118
cmp LETTER, KB_BKSP ;skip Backspace
120
cmp LETTER, KB_ESC ;stop with Escape
123
;Check if the player have already tried this letter
124
mov cl, play_tried_len
125
mov bx, offset play_tried_letters
129
je play_main_loop ;Letter already in the list -> play_main_loop
135
;The letter is not in the list (play_tried_letters), so we add it
136
mov cl, play_tried_len
137
mov bx, offset play_tried_letters
140
cmp [bx], ' ' ;Search a space
141
je play_add_letter_add
146
jmp play_add_letter_end ;Something is wrong... No more place !
151
;Check if the letter is in the word
152
mov cl, play_word_len
154
mov bx, offset play_word
159
je play_check_word_ok
164
;The letter is not in the word
166
mov SOUND, offset SND_GAME_BAD_LTTR
168
jmp play_check_word_end
170
mov SOUND, offset SND_GAME_GOOD_LTTR
176
je play_eog ;Hanged x_x
186
mov GAME_STATUS, GAME_STATUS_ABORT
200
play_word db "------------------------------"
202
play_word_max_len equ 30
204
play_gword db "------------------------------"
205
play_tried_letters db "--------------------------"
206
play_tried_len equ 26
211
game_help db 0xDA,"A-Z",0xBF," Try a letter "
212
db " ",0xDA,"Esc",0xBF," End the game$"
216
;=========================================================== _game_init() ====
217
;; Initializes the game.
219
;; NOTE: Called by the _play() function.
233
;Put the length of WORD in play_word_len
238
mov play_word_len, al
240
;Put the WORD in play_word
243
mov MEMCPY_DEST, offset play_word
248
;Fill play_tried_letters with spaces
249
mov bx, offset play_tried_letters
250
mov cl, play_tried_len
259
;Init the play_lives to 10 (with gibbet) or 6 (without gibbet)
260
mov play_lives, 10 ;FIXME
272
;======================================================== _print_gibbet() ====
273
;; Prints the gibbet with remaining lives.
276
;; call _print_gibbet
287
;Calculate the address of the gibbet that fit with the remaining lives
291
mov bl, GIBBET_HEIGHT
298
mov bx, offset HANGMAN_LIVES_10
302
mov cl, GIBBET_HEIGHT
306
mov POS_X, COLS - GIBBET_WIDTH - 2
307
mov POS_Y, (ROWS - GIBBET_HEIGHT) / 2 + (header_height - 1) / 2
315
jne print_gibbet_loop
327
;========================================================= _print_gword() ====
328
;; Prints the guessed word (e.g. H _ _ _ _ _ N).
342
;Copy the word in play_gword
345
mov MEMCPY_DEST, offset play_gword
351
mov cl, play_word_len
353
mov bx, offset play_gword
358
mov ch, play_tried_len
360
mov bx, offset play_tried_letters
368
jne print_gword_mkloop1
370
print_gword_lnil: ;Letter Not In List
373
jmp print_gword_mkloopend
375
print_gword_lil: ;Letter In List
378
print_gword_mkloopend:
382
jne print_gword_mkloop
385
mov POS_Y, ROWS / 2 + (header_height - 1) - 5
386
mov POS_X, COLS / 2 - GIBBET_WIDTH + 3
387
mov al, play_word_len
389
mov bx, offset play_gword
390
mov cl, play_word_len
400
jne print_gword_prnloop
412
;================================================= _print_tried_letters() ====
413
;; Print the letters that the player have already tried (e.g. A U I O W).
416
;; call _print_tried_letters
419
_print_tried_letters:
427
;Calculate the length of the string
429
mov bx, offset play_tried_letters
432
je prn_tried_strlen_end
436
prn_tried_strlen_end:
438
;Calculate the cursor position
439
mov POS_Y, ROWS / 2 + (header_height - 1) - 2
440
mov POS_X, COLS / 2 - GIBBET_WIDTH + 3
446
mov bx, offset play_tried_letters
471
;========================================================== _game_anima() ====
472
;; Displays an animation when the player loose or win.
487
cmp GAME_STATUS, GAME_STATUS_WIN
489
mov SOUND, offset SND_GAME_DIE
490
jmp game_anima_sndend
492
mov SOUND, offset SND_GAME_GG
499
;Print the help message
500
mov HELP_STR, offset game_anima_help
503
;Flush the input buffer
509
mov cl, play_word_len
510
mov bx, offset play_word
513
mov POS_Y, header_height + GIBBET_HEIGHT + 5
523
jne game_anima_pnrloop
525
;Loop until the player press any key
528
cmp GAME_STATUS, GAME_STATUS_WIN
530
mov dx, offset HANGMAN_GAMEOVER_00
533
mov dx, offset HANGMAN_GOODGAME_00
540
;Print the animation (step 00)
541
mov cl, GIBBET_HEIGHT
543
mov POS_X, (COLS - GIBBET_WIDTH) / 2
544
mov POS_Y, header_height + 3
545
game_anima_prnloop00:
552
jne game_anima_prnloop00
573
jne game_anima_chrend
574
mov GAME_STATUS, GAME_STATUS_ABORT
588
game_anima_help db "Press any key to continue "
589
db " ",0xDA,"Esc",0xBF," End the game$"