1 ; ------------------------------------------------------------------
2 ; Geography-based hangman game for MikeOS
4 ; At the end of this file you'll see a list of 256 cities (in
5 ; lower-case to make the game code simpler). We get one city at
6 ; random from the list and store it in a string.
8 ; Next, we create another string of the same size, but with underscore
9 ; characters instead of the real ones. We display this 'work' string to
10 ; the player, who tries to guess characters. If s/he gets a char right,
11 ; it is revealed in the work string.
13 ; If s/he gets gets a char wrong, we add it to a list of misses, and
14 ; draw more of the hanging man. Poor bloke.
15 ; ------------------------------------------------------------------
19 %INCLUDE "mikedev.inc"
27 ; First, reset values in case user is playing multiple games
29 mov di, real_string
; Full city name
34 mov di, work_string
; String that starts as '_' characters
39 mov di, tried_chars
; Chars the user has tried, but aren't in the real string
44 mov byte [tried_chars_pos
], 0
45 mov byte [misses
], 1 ; First miss is to show the platform
48 mov ax, title_msg
; Set up the screen
51 call os_draw_background
55 call os_get_random
; Get a random number
57 mov bl, cl ; Store in BL
60 mov si, cities
; Skip number of lines stored in BL
66 lodsb ; Find a zero to denote end of line
73 mov di, real_string
; Store the string from the city list
79 mov dx, ax ; DX = number of '_' characters to show
84 cmp dx, 5 ; Give first char if it's a short string
87 mov ax, hint_msg_1
; Tell player about the hint
95 mov ax, title_msg
; Redraw screen
98 call os_draw_background
100 mov byte al, [real_string
] ; Copy first letter over
101 mov byte [work_string
], al
105 call fix_spaces
; Add spaces to working string if necessary
108 call show_tried_chars
; Update screen areas
112 cmp byte [misses
], 11 ; See if the player has lost
115 call os_wait_for_key
; Get input
120 mov bl, al ; Store character temporarily
122 mov cx, 0 ; Counter into string
123 mov dl, 0 ; Flag whether char was found
127 cmp al, 0 ; End of string?
129 cmp al, bl ; Find char entered in string
131 inc cx ; Move on to next character
137 inc dl ; Note that at least one char match was found
139 add di, cx ; Update our underscore string with char found
146 mov si, real_string
; If the strings match, the player has won!
148 call os_string_compare
151 cmp dl, 0 ; If char was found, skip next bit
154 call update_tried_chars
; Otherwise add char to list of misses
162 call os_wait_for_key
; Wait for keypress
170 lost_game: ; After too many misses...
172 .
loop: ; Wait for keypress
190 add_underscores: ; Create string of underscores
193 mov cx, dx ; Size of string
199 ; Copy any spaces from the real string into the work string
219 ; Here we check the list of wrong chars that the player entered previously,
220 ; and see if the latest addition is already in there...
225 call os_find_char_in_string
227 jne .nothing_to_add
; Skip next bit if char was already in list
231 mov byte al, [tried_chars_pos
] ; Move into the list
234 inc byte [tried_chars_pos
]
236 inc byte [misses
] ; Knock up the score
243 mov bl, BLACK_ON_WHITE
286 mov bl, BLACK_ON_WHITE
297 mov si, tried_chars_msg
313 mov bl, WHITE_ON_GREEN
336 .win_msg
db 'Yay! Hit enter to play again', 0
341 mov bl, WHITE_ON_LIGHT_RED
364 .lose_msg
db 'Doh! Hit enter to play again', 0
368 ; Draw the hangman box and appropriate bits depending on the number of misses
373 mov bl, BLACK_ON_WHITE
401 cmp byte [misses
], 10
403 cmp byte [misses
], 11
455 .4: ; Support for beam
493 .2: ; Support for pole
513 .1_t
db '-------------', 0
517 .5_t db '________
', 0
527 title_msg
db 'MikeOS Hangman', 0
528 footer_msg
db 'Press Esc to exit', 0
530 hint_msg_1
db 'Short word this time, so you', 0
531 hint_msg_2
db 'get the first letter for free!', 0
533 help_msg_1
db 'Can you guess the city name', 0
534 help_msg_2
db 'that fits the spaces beneath?', 0
535 help_msg_3
db 'Press keys to guess letters,', 0
536 help_msg_4
db 'but you only have 10 chances!', 0
538 real_string times
50 db 0
539 work_string times
50 db 0
541 tried_chars_msg
db 'Tried characters...', 0
543 tried_chars times
255 db 0
554 db 'andorra la vella', 0
577 db 'bandar seri begawan', 0
602 db 'santo domingo', 0
620 db 'saint georges', 0
621 db 'guatemala city', 0
625 db 'port au prince', 0
675 db 'yaren district', 0
732 db 'dar es salaam', 0
736 db 'port of spain', 0
756 db 'st petersburg', 0
766 db 'san francisco', 0
777 db 'rio de janeiro', 0
809 ; ------------------------------------------------------------------