hangman8086-devs team mailing list archive
-
hangman8086-devs team
-
Mailing list archive
-
Message #00006
[Merge] lp:~hangman8086-devs/hangman8086/competition-mode into lp:hangman8086
Fabien LOISON (FLOZz) has proposed merging lp:~hangman8086-devs/hangman8086/competition-mode into lp:hangman8086.
Requested reviews:
Hangman 8086 Developers (hangman8086-devs)
For more details, see:
https://code.launchpad.net/~hangman8086-devs/hangman8086/competition-mode/+merge/65092
--
https://code.launchpad.net/~hangman8086-devs/hangman8086/competition-mode/+merge/65092
Your team Hangman 8086 Developers is requested to review the proposed merge of lp:~hangman8086-devs/hangman8086/competition-mode into lp:hangman8086.
=== modified file 'Makefile'
--- Makefile 2011-05-26 14:19:39 +0000
+++ Makefile 2011-06-18 14:28:29 +0000
@@ -20,6 +20,7 @@
cd buildenv/ && ./makeenv.sh
debug:
+ mkdir -p ./buildenv/MyBuild/
rm -f ./buildenv/MyBuild/*
cp *.asm *.res ./buildenv/MyBuild/
mv ./buildenv/MyBuild/main.asm ./buildenv/MyBuild/00main.asm
=== modified file 'asciiart.res'
--- asciiart.res 2011-05-26 14:19:39 +0000
+++ asciiart.res 2011-06-18 14:28:29 +0000
@@ -52,6 +52,19 @@
+;============================================================ Header Logo ====
+gameover db " _____ ____ $"
+ db " / ____| / __ \ $"
+ db " | | __ __ _ _ __ ___ ___ | | | |__ _____ _ __ $"
+ db " | | |_ |/ _` | '_ ` _ \ / _ \ | | | |\ \ / / _ \ '__|$"
+ db " | |__| | (_| | | | | | | __/ | |__| | \ V / __/ | $"
+ db " \_____|\__,_|_| |_| |_|\___| \____/ \_/ \___|_| $"
+
+gameover_len equ 56
+gameover_height equ 6
+
+
+
;========================================================= Startup Screen ====
startup_scr db " ____ _____ ____ _____ _____ _ __ __ $"
db " | __ )| ____/ ___|_ _| ____| / \ | \/ | $"
=== modified file 'game.asm'
--- game.asm 2011-05-29 15:04:29 +0000
+++ game.asm 2011-06-18 14:28:29 +0000
@@ -52,6 +52,8 @@
GAME_STATUS_WIN equ 1
GAME_STATUS_ABORT equ 2
+SCORE dw 0
+PLAYER dw "UNNAMED "
;============================================================ _play(WORD) ====
@@ -59,6 +61,7 @@
;; Usage:
;; mov WORD, offset <word>
+;; mov PLAYER, offset <playername>
;; call _play
;; Function args:
@@ -87,9 +90,9 @@
play_main_loop:
call _clear_working
call _print_gword
-
call _print_tried_letters
call _print_gibbet
+ call _print_score
;Check if the play win
;For checking we search underscores in play_gword... It is not very
@@ -474,6 +477,75 @@
+;========================================================= _print_score() ====
+;; Print the score in competition mode).
+
+;; Usage:
+;; call _print_tried_letters
+
+
+_print_score:
+
+;Backup registers
+push ax
+push bx
+push cx
+push dx
+
+;Check if we are in competition mode
+cmp MODE, MODE_COMPETITION
+jnz prn_score_end
+
+;Set the scorebar
+mov ah, 0x07
+mov al, 0 ; Clear
+mov bh, COLOR_SCORE
+mov ch, header_height + 1 ;y1
+mov cl, 0 ;x1
+mov dh, header_height + 1 ;y2
+mov dl, COLS ;x2
+int 0x10
+
+;Paste the player name
+mov MEMCPY_SRC, offset PLAYER
+mov MEMCPY_DEST, offset prn_score_str
+add MEMCPY_DEST, 2
+mov MEMCPY_LEN, 8
+call _memcpy
+
+;Convert the score into string and paste it
+mov ax, SCORE
+mov I2S_INT, ax
+call _inttostr
+mov MEMCPY_SRC, offset I2S_STR
+add MEMCPY_DEST, 11
+mov MEMCPY_LEN, 4
+call _memcpy
+
+;Print the string
+mov POS_X, 0
+mov POS_Y, header_height + 1
+call _move_cursor
+mov ah, 0x09
+mov dx, offset prn_score_str
+int 0x21
+
+prn_score_end:
+
+;Restore registers
+pop dx
+pop cx
+pop bx
+pop ax
+
+ret
+
+
+;Data
+prn_score_str db " ",0xC0,"12345678",0xD9," ",0xC0,"1234",0xD9,"$"
+
+
+
;========================================================== _game_anima() ====
;; Displays an animation when the player loose or win.
=== modified file 'main.asm'
--- main.asm 2011-05-29 12:22:53 +0000
+++ main.asm 2011-06-18 14:28:29 +0000
@@ -53,6 +53,8 @@
COLOR_HEADER equ 00101111b ;Color of the Header an help area
COLOR_ACTIVE equ 00001111b ;Color of the Menu/Game/Animation area
COLOR_CURSOR equ 00000010b ;Color of the menu cursor
+COLOR_FIELD equ 00101111b ;Color of the input fields
+COLOR_SCORE equ 00000010b ;Color of the score bar
@@ -65,6 +67,7 @@
include "game.asm" ;Contains the game functions.
include "singlepl.asm" ;Contains the single player mode.
include "options.asm" ;Contains the options menu.
+include "modesel.asm" ;Contains the mode selection menu.
;RESOURCE
include "asciiart.res" ;Contains the ASCII art of the game.
=== modified file 'mainfunc.asm'
--- mainfunc.asm 2011-06-14 15:39:14 +0000
+++ mainfunc.asm 2011-06-18 14:28:29 +0000
@@ -37,7 +37,7 @@
;;
;; Index:
;; _draw_ui() -- Draws the user interface on the screen.
-;; _clear_working -- Clears the working part of the screen.
+;; _clear_working() -- Clears the working part of the screen.
;; _print_header() -- Prints the HANGMAN logo on the screen.
;; _print_help(HELP_STR) -- Prints the help message on the bottom of
;; the screen.
@@ -51,6 +51,10 @@
;; MEMCPY_LEN)
;; _strlen(STRLEN_STR) -- Counts the number of bytes that composes
;; a string.
+;; _inttostr(I2S_INT) -- Convert integers into strings.
+;; _input_field(IF_MSG, -- Display an input field.
+;; IF_MAXLEN,
+;; IF_EWD)
;;
@@ -283,7 +287,7 @@
;; call _input_letter
;; Returns:
-LETTER db 0 ;An upper case letter
+LETTER db 0 ;An upper case letter (or KB_ESC, KB_BKSP, KB_ENTER).
_input_letter:
@@ -473,6 +477,7 @@
ret
+<<<<<<< TREE
;Args:
I2S_INT db 0 ;The number to convert
@@ -497,3 +502,234 @@
ret
+=======
+
+;===================================================== _inttostr(I2S_INT) ====
+;; Convert integers into strings.
+
+;; Usage:
+;; mov I2S_INT, <int>
+;; call _inttostr
+
+;; Args:
+I2S_INT dw 0 ;The integer to convert
+
+;; Return:
+I2S_STR dw "0000" ;The result string
+
+
+_inttostr:
+
+;Backup registers
+push ax
+push bx
+push cx
+push dx
+
+;"Split" the number
+mov ax, I2S_INT
+mov bx, 10
+mov cx, 4
+i2s_split_loop:
+mov dx, 0
+div bx
+push dx
+dec cx
+cmp cx, 0
+jnz i2s_split_loop
+
+;Convert in string
+mov bx, offset I2S_STR
+mov cx, 4
+i2s_str_loop:
+pop ax
+add ax, '0'
+mov [bx], al
+inc bx
+dec cx
+cmp cx, 0
+jnz i2s_str_loop
+
+;Restore registers
+pop dx
+pop cx
+pop bx
+pop ax
+
+ret
+
+
+
+;================================ _input_field(IF_MSG, IF_MAXLEN, IF_EWD) ====
+;; Display an input field.
+
+;; Usage:
+;; mov IF_MSG, offset <src>
+;; mov IF_MAXLEN, <len>
+;; mov IF_EWD, <0/1>
+;; call _input_field
+
+;; Function args:
+IF_MSG dw 0 ; The message address (must end with '$')
+IF_MAXLEN db 0 ; The maximum len of the input (max = 30)
+IF_EWD db 0 ; End with $ ? (0 = False, 1 = True)
+
+;; Returns:
+IF_WORD db "-------------------------------" ; The input word
+
+
+_input_field:
+
+;Backup registers
+push ax
+push bx
+push cx
+push dx
+
+;Clear the screen (draw the UI)
+call _draw_ui
+mov HELP_STR, offset if_help
+call _print_help
+
+;Fill IF_WORD with spaces or $
+mov cl, 31
+mov bx, offset IF_WORD
+if_fill_word_loop:
+ cmp IF_EWD, 1 ; ' ' or '$' ?
+ je if_fill_word_dollard
+ mov [bx], ' '
+ jmp if_fill_word_dollard_end
+ if_fill_word_dollard:
+ mov [bx], '$'
+ if_fill_word_dollard_end:
+ inc bx
+ dec cl
+ cmp cl, 0
+ jne if_fill_word_loop
+
+;Display the message
+ ;Center the message
+ mov ax, IF_MSG
+ mov STRLEN_STR, ax
+ call _strlen
+ mov ah, 0
+ mov al, STRLEN_LEN
+ mov bl, 2
+ div bl
+ mov ah, COLS / 2
+ sub ah, al
+ mov POS_X, ah
+ mov POS_Y, header_height
+ add POS_Y, 5
+ call _move_cursor
+ ;Print the message
+ mov ah, 0x09
+ mov dx, IF_MSG
+ int 0x21
+
+;Display the field
+ ;Center the field
+ mov ah, 0
+ mov al, IF_MAXLEN
+ mov bl, 2
+ div bl
+ mov ah, COLS / 2
+ sub ah, al
+ mov POS_X, ah
+ add POS_Y, 2
+ call _move_cursor
+ ;print the field
+ mov ah, 0x07
+ mov al, 0 ; Clear
+ mov bh, COLOR_FIELD ; Color
+ mov ch, POS_Y ; x1
+ mov cl, POS_X ; x1
+ mov dh, POS_Y ; y2
+ mov dl, POS_X ; x2
+ add dl, IF_MAXLEN ; ~~
+ inc dl ; ~~
+ int 0x10
+
+mov if_wlen, 0
+
+;Intput field main loop
+if_loop:
+ call _input_letter
+ cmp LETTER, KB_ENTER ; Validate
+ je if_loop_end
+ cmp LETTER, KB_ESC ; skip esc
+ je if_loop
+ cmp LETTER, KB_BKSP ; Remove last letter
+ je if_loop_bksp
+
+ ;Add the letter if the buffer is not full
+ mov ah, IF_MAXLEN
+ cmp if_wlen, ah
+ je if_loop
+
+ ;buff
+ mov bx, offset IF_WORD
+ mov ah, 0
+ mov al, if_wlen
+ add bx, ax
+ mov al, LETTER
+ mov [bx], al
+ inc if_wlen
+
+ ;disp
+ inc POS_X
+ call _move_cursor
+ mov ah, 0x06
+ mov dl, LETTER
+ int 0x21
+
+ jmp if_loop
+
+ if_loop_bksp:
+ cmp if_wlen, 0 ;empty
+ je if_loop
+
+ ;buff
+ mov bx, offset IF_WORD
+ mov ah, 0
+ mov al, if_wlen
+ add bx, ax
+ dec bx
+ cmp IF_EWD, 1
+ je if_loop_ewd
+ mov [bx], ' '
+ jmp if_loop_ewdend
+ if_loop_ewd:
+ mov [bx], '$'
+ if_loop_ewdend:
+ dec if_wlen
+
+ ;disp
+ call _move_cursor
+ mov ah, 0x06
+ mov dl, ' '
+ int 0x21
+ dec POS_X
+
+ jmp if_loop
+
+ if_loop_end:
+
+;Restore registers
+pop dx
+pop cx
+pop bx
+pop ax
+
+ret
+
+
+;Var
+if_wlen db 0
+
+;Help
+if_help db 0xDA,"A-Z",0xBF," Try a letter ",0xDA,"Enter",0xBF," Validate"
+ db " $"
+
+
+>>>>>>> MERGE-SOURCE
=== added file 'modesel.asm'
--- modesel.asm 1970-01-01 00:00:00 +0000
+++ modesel.asm 2011-06-18 14:28:29 +0000
@@ -0,0 +1,235 @@
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; __ __ _______ __ _ _______ __ __ _______ __ _ ;;
+;; | | | || _ || | | || || |_| || _ || | | | ;;
+;; | |_| || |_| || |_| || ___|| || |_| || |_| | ;;
+;; | || || || | __ | || || | ;;
+;; | || || _ || || || || || _ | ;;
+;; | _ || _ || | | || |_| || ||_|| || _ || | | | ;;
+;; |__| |__||__| |__||_| |__||_______||_| |_||__| |__||_| |__| ;;
+;; ;;
+;; ;;
+;; 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 mode) 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 mode selection menu.
+;;
+;; Index:
+;; _mode_menu() -- Displays the mode selection menu.
+;; _draw_mode_menu() -- (Re)draws the mode selection menu on the screen.
+;;
+
+
+
+MODE db 0
+MODE_PRACTICE equ 0
+MODE_COMPETITION equ 1
+
+
+
+;=========================================================== _mode_menu() ====
+;; Displays the mode selection menu.
+
+;; Using:
+;; call _mode_menu
+
+
+_mode_menu:
+
+;Flush the input buffer
+mov ah, 0x0C
+mov al, 0
+int 0x21
+
+;Set the variables to theire default
+mov MODE, MODE_PRACTICE
+mov mode_menu_selected, MODE_MENU_PRACTICE
+
+;Draw the UI
+call _draw_ui
+
+;Print the help message
+mov HELP_STR, offset mode_menu_help
+call _print_help
+jmp mode_menu_refresh
+
+mode_menu_snd:
+ mov SOUND, offset SND_MENU_CH_ITEM
+ call _draw_mode_menu
+ call _play_sound
+ jmp mode_menu_loop
+
+mode_menu_refresh:
+ call _draw_mode_menu
+
+mode_menu_loop:
+ ;Wait for input
+ mov ah, 0x00
+ int 0x16
+
+ cmp al, ' ' ;Space
+ jz mode_menu_validate
+ cmp al, 0x0D ;Enter
+ jz mode_menu_validate
+ cmp ah, 0x50 ;Down arrow
+ jz mode_menu_movedown
+ cmp ah, 0x48 ;Up arrow
+ jz mode_menu_moveup
+ cmp ax, 0x011B ;Escape
+ jz mode_menu_backtomain
+
+ ;Not a valid input
+ jmp mode_menu_loop
+
+ ;Move down
+ mode_menu_movedown:
+ inc mode_menu_selected
+
+ cmp mode_menu_selected, mode_menu_items_numb
+ jnz mode_menu_snd
+
+ mov mode_menu_selected, 0
+ jmp mode_menu_snd
+
+ ;Move up
+ mode_menu_moveup:
+ dec mode_menu_selected
+
+ cmp mode_menu_selected, -1
+ jnz mode_menu_snd
+
+ mov mode_menu_selected, mode_menu_items_numb
+ dec mode_menu_selected
+ jmp mode_menu_snd
+
+ ;Validate
+ mode_menu_validate:
+ mov SOUND, offset SND_MENU_VALID
+ call _play_sound
+
+ ;Practice
+ cmp mode_menu_selected, MODE_MENU_PRACTICE
+ jnz mode_menu_practice_end
+ mov MODE, MODE_PRACTICE
+ jmp mode_menu_end
+ mode_menu_practice_end:
+
+ ;Competition
+ cmp mode_menu_selected, MODE_MENU_COMPETITION
+ jnz mode_menu_competition_end
+ mov MODE, MODE_COMPETITION
+ jmp mode_menu_end
+ mode_menu_competition_end:
+
+ ;Back
+ cmp mode_menu_selected, MODE_MENU_BACK
+ jnz mode_menu_back_end
+ jmp mode_menu_backtomain
+ mode_menu_back_end:
+
+ jmp mode_menu_refresh
+
+mode_menu_backtomain:
+mov MODE, -1
+
+mode_menu_end:
+
+ret
+
+
+
+;====================================================== _draw_mode_menu() ====
+;; (Re)draws the mdoe selection menu on the screen.
+
+;; Using:
+;; call _draw_mode_menu
+
+
+_draw_mode_menu:
+
+;Center the menu
+mov pos_x, (COLS-mode_menu_items_len)/2
+mov pos_y, header_height
+add pos_y, 4
+
+;Prepare the print
+mov ah, 0x09
+mov dx, offset mode_menu_items
+
+mov cx, mode_menu_items_numb
+
+;Draw items
+draw_mode_menu_loop:
+ call _move_cursor
+ int 0x21
+ add pos_y, 2
+ add dx, mode_menu_items_len
+ dec cx
+ cmp cx, 0
+ jne draw_mode_menu_loop
+
+
+;Display the cursor on the selected item
+mov pos_y, header_height
+add pos_y, 4
+mov ah, 0x00
+mov al, mode_menu_selected
+mov bl, 2
+mul bl
+add pos_y, al
+
+call _move_cursor
+
+mov ah, 0x09
+mov al, 0x10
+mov bh, 0
+mov bl, COLOR_CURSOR ; color
+mov cx, 1
+int 0x10
+
+ret
+
+
+
+;============================ Vars for _mode_menu() and _draw_mode_menu() ====
+mode_menu_selected db 0 ;The selected item of the menu
+
+
+
+;=========================== Datas for _mode_menu() and _draw_mode_menu() ====
+mode_menu_help db 0xDA,0x18,0x19,0xBF," Navigate ",0xDA,"Enter",0xBF
+ db " Validate ",0xDA
+ db "Esc",0xBF, " Quit$"
+
+mode_menu_items db " Practice $"
+ db " Competition $"
+ db " Back $"
+mode_menu_items_len equ 16
+mode_menu_items_numb equ 3
+
+MODE_MENU_PRACTICE equ 0
+MODE_MENU_COMPETITION equ 1
+MODE_MENU_BACK equ 2
+
+
=== modified file 'playsnd.asm'
--- playsnd.asm 2011-05-26 14:19:39 +0000
+++ playsnd.asm 2011-06-18 14:28:29 +0000
@@ -36,12 +36,12 @@
;; Contains the function for playing sounds.
;;
;; Index:
-;; _play_sound() -- Plays a sound.
+;; _play_sound(SOUND) -- Plays a sound.
;;
-;========================================================== _play_sound() ====
+;===================================================== _play_sound(SOUND) ====
;; Plays a sound.
;; Usage:
=== modified file 'singlepl.asm'
--- singlepl.asm 2011-05-31 13:03:40 +0000
+++ singlepl.asm 2011-06-18 14:28:29 +0000
@@ -56,6 +56,29 @@
push cx
push dx
+;Get the mode
+call _mode_menu
+
+;Back to the main menu if necessary
+cmp MODE, -1
+je sp_end
+
+;Ask the players name if the competition mode is selected
+cmp MODE, MODE_COMPETITION
+jne sp_plname_end
+mov IF_MSG, offset sp_msg_plname
+mov IF_MAXLEN, 8
+mov IF_EWD, 0
+call _input_field
+mov MEMCPY_SRC, offset IF_WORD
+mov MEMCPY_DEST, offset PLAYER
+mov MEMCPY_LEN, 8
+call _memcpy
+;Set the score to 0
+mov SCORE, 0
+sp_plname_end:
+nop
+
sp_start:
;Get a random word from the dict
;"Random" number
@@ -89,9 +112,30 @@
call _play
;Check the game status
-cmp GAME_STATUS, GAME_STATUS_ABORT
+cmp GAME_STATUS, GAME_STATUS_ABORT ;Abort ?
je sp_end
-jmp sp_start
+
+cmp GAME_STATUS, GAME_STATUS_WIN ; Win && competition ?
+jnz sp_win_end
+cmp MODE, MODE_COMPETITION
+jnz sp_start
+
+mov ah, 0
+mov al, play_lives
+cmp OPTION_GIBBET, OPTION_GIBBET_OFF
+jnz sp_gibbet_end
+add ax, 6 ;bonus
+sp_gibbet_end:
+add SCORE, ax
+
+sp_win_end:
+
+cmp GAME_STATUS, GAME_STATUS_LOOSE ; Loose && competition ?
+jnz sp_start
+cmp MODE, MODE_COMPETITION
+jnz sp_start
+
+call _sp_gameover
sp_end:
@@ -104,3 +148,64 @@
ret
+;Datas
+sp_msg_plname db "Please enter your name:$"
+
+
+
+;========================================================= _sp_gameover() ====
+;; Prints the game over screen
+
+;; Usage:
+;; call _sp_gameover
+
+
+_sp_gameover:
+
+call _draw_ui
+
+mov POS_X, (COLS-gameover_len)/2
+mov POS_Y, header_height + 3
+
+mov ah, 0x09
+mov dx, offset gameover
+
+sp_gameover_loop:
+ call _move_cursor
+ int 0x21
+ inc POS_Y
+ add dx, gameover_len
+ cmp POS_Y, gameover_height + header_height + 3
+ jne sp_gameover_loop
+
+add POS_Y, 2
+mov POS_X, (COLS-sp_go_score_len)/2
+call _move_cursor
+
+mov ax, SCORE
+mov I2S_INT, ax
+call _inttostr
+
+mov MEMCPY_SRC, offset I2S_STR
+mov MEMCPY_DEST, offset sp_go_score
+add MEMCPY_DEST, 15
+mov MEMCPY_LEN, 4
+call _memcpy
+
+mov ah, 0x09
+mov dx, offset sp_go_score
+int 0x21
+
+;wait
+mov ah, 0x86
+mov cx, 64
+int 0x15
+
+ret
+
+
+;datas
+sp_go_score db "Your score is: 1234$"
+sp_go_score_len equ 20
+
+
=== modified file 'sounds.res'
--- sounds.res 2011-06-14 15:39:14 +0000
+++ sounds.res 2011-06-18 14:28:29 +0000
@@ -33,7 +33,7 @@
;;
-;; Contains the sounds.
+;; Contains the sounds ressources.
;;
=== modified file 'words.res'
--- words.res 2011-06-07 15:36:09 +0000
+++ words.res 2011-06-18 14:28:29 +0000
@@ -33,7 +33,7 @@
;;
-;; Contains the word list for the single player mode.
+;; Contains the word lists for the single player mode.
;;
Follow ups