汇编语言课程设计 打字游戏(源程序)

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

INCLUDE YLIB.H
CURSOR MACRO ROW,COL ;设置光标位置
MOV AH, 02H ;
MOV BH, 00H ;页号
MOV DH, ROW ;行
MOV DL, COL ;列
INT 10H
ENDM
;-------------------------------------------------
Init_boarder macro row, col, char, dhdl, count ;边框的设置
Local ll
mov cx, count
mov dh, row
mov dl, col
ll: mov ah, 02h
mov bh, 00h ;页号
int 10h
push cx
mov ah, 0ah
mov al, char ;输出字符
mov bh, 00h ;页号
mov cx, 01h ;在该位置上输入一次
int 10h
pop cx
inc dhdl ;行或列递增
loop ll
endm
; ---------------------------------------------------
clear_screen macro top, left, bottom, right; 清屏宏定义
mov ah, 06h
mov al, 00h ;初始化窗口
mov bh, 07h ;卷入行属性
mov ch, top ;左上行
mov cl, left ;左上列
mov dh, bottom ;右下行
mov dl, right ;右下列
int 10h
CURSOR 0,0
endm
; ----------------------------------------------------
TIME MACRO ROW,COL,M,D,MESS;
CURSOR ROW,COL
PUSH DX
PUSH AX
MOV AH, 09H
LEA DX,MESS
INT 21H
POP AX
POP DX
MOV AL,CL
MOV AH,CH
MOV DX,0FFFFH
CALL WRITEINT
MOV AL,M
MOV AH,0
CALL WRITEINT
MOV AL,D
MOV AH,0
CALL WRITEINT



ENDM

; ----------------------------------------------------
menu macro row, col, text; 菜单显示宏定义
CURSOR ROW,COL
mov ah, 09h
lea dx, text
int 21h
endm
; ======================================================
Data segment
ZK db "WELCOME TO PLAY$"
DATE DB "Date:$"

MESS0 DB "ENTER THE PASSWORD(ONLY THREE CHANCES):$"
MESS1 DB "PASSWORD IS WRONG!$"
MESS2 DB "YOUR SCORE IS:$"
MESS3 DB "THE NUMBER OF THE LETTERS ARE:$"
MESS4 DB "THE RIGHT NUMBER OF THE LETTERS ARE:$"
MESS5 DB "PRESS ANY KEY TO CONTINUE.......$"
X DB "123"
Y DB 11,?,11 DUP(?)
MONTH DB ?
DAY DB ?
EASY DB 'Easy$';设置难度
NORMAL DB 'Normal$'
HARD DB 'Hard$'
FL DB 'enter the FIRST letter to choose level:$'
RIGHT DW 0
SCORE DW 0
NUM DW 0
B DB ?;BEGIN TIME
ET DB ?;END TIME
mes0 db "Press Enter key to continue.......$"
mes1 db "When a letter is dropping,please hit it!$"
mes2 db "Press space key to pause!$"
mes3 db "Press ESC key to return main interface!$"
mes4 db "Press letter 'E' to exit!$"
Speed dw 9000H
Letters db "jwmilzoeucgpravskntxhdyqfb"
db "iytpkwnxlsvxrmofzhgaebudjq"
db "nwimzoexrphysfqtvdcgljukda"
Present_position db 1
db 0 ;
Data ends
; =========================================================
code segment
main proc far
assume cs: code, ds: data
start: mov ax, data
mov ds, ax
mov es, ax

mov cx, 1000h
mov ah, 01h
int 10h
CLS
MOV BL,6

MOV CX,3;输入密码错误达3次退出
TWO:

INC BL
MENU BL,15D,MESS0
PUSH CX

LEA DX,Y
MOV AH,0AH
INT 21H
XOR CX,CX
MOV AL,3 ;这个3为X中密码的个数
CMP AL,[Y+1]
JNE WRONG
MOV CL,AL
LEA SI,Y+2
LEA DI,X

ONE:
MOV AL,[SI]
CMP [DI],AL
JNZ WRONG
INC SI
INC DI
LOOP ONE
LEA DX,MESS1
MOV AH,09H
INT 21H
JMP KAISHI
WRONG:
INC BL
MENU BL,15D,MESS1
POP CX
LOOP TWO
JMP EXIT

;
KAISHI:
clear_screen 00d, 00d, 24d, 79d ;
Init_boarder 00d, 00d, 0ah, dl, 80d
Init_boarder 24d, 00d, 0ah, dl, 80d
Init_boarder 00d, 00d, 0ah, dh, 25d
Init_boarder 00d, 79d, 0ah, dh, 25d ;

menu 05d, 15d, ZK ; 显示菜单

menu 09d, 15d, mes0
menu 11d, 18d, mes1
menu 13d, 18d, mes2
menu 15d, 18d, mes3
menu 17d, 15d, mes4
MOV AH,2AH
INT 21H
MOV MONTH,DH
MOV DAY,DL
TIME 07H,15D,MONTH,DAY,DATE

CURSOR 22D,33D;设置光标位置

keyin: mov ah, 07h
int 21h
cmp al, 0dh ;
je begin ;
cmp al, 'E' ;
je exit ;
jmp keyin ;


exit:
CLS
CURSOR 0,0
mov ax, 4c00h
int 21h


begin:
MOV SCORE,0
MOV RIGHT,0
MOV NUM ,0
clear_screen 01d, 01d, 23d, 78d ; 清屏
CALL LEVEL
MOV SPEED,AX
CLS
Init_boarder 00d, 00d, 0ah, dl, 80d
Init_boarder 24d, 00d, 0ah, dl, 80d
Init_boarder 00d, 00d, 0ah, dh, 25d
Init_boarder 00d, 79d, 0ah, dh, 25d ;
Init_boarder 23d, 01d, 01h, dl, 78d ;

CURSOR 01D,01D ;字母最先显示的位置 ;

mov cx, 78
lea si, letters
nextletter:
mov ah, 02h ; 显示字母
mov dl, [si]
int 21h
inc si
loop nextletter
MOV AH,2CH
INT 21H
MOV B,DH ;记录游戏开始的时间

start_game:
mov ah, 2ch
int 21h
MOV ET,DH ;记录游戏时间
inc dl ;
cmp dl, 78
jna sg1
sub dl, 78
sg1: mov present_position, dl
lea di, letters
add di, word ptr present_position ;
dec di ;
mov dl, present_position ;
mov ah, 02h
mov bh, 00h
mov dh, 01h
int 10h ;

mov cx, 21d ;循环21次,掉落21行
nextrow: push cx
mov cx, speed ;下落一格给你考虑的时间,speed越大给你考虑的时间就越长,相对就更简单
wait_for_key: ;
push cx
mov cx,1000

delay:
loop delay ;

push dx
mov ah, 06h ; 从键盘输入字符
mov dl, 0ffh
int 21h

pop dx
jz pass

cmp al, 1bh ; 如果键入ESC,则返回SHOWSCORE
JE SHOWSCORE
cmp al, " " ; 如果键入SPACE,则游戏暂停
jne pass0
pause: push dx ; 暂停处理
mov ah, 06h
mov dl, 0ffh
int 21h
pop dx
cmp al, " " ;
jne pause ;
jmp pass

pass0: ADD NUM,1 ;记录按字母的个数
cmp al,[di] ; 输入字母正确!则字母消失
je disappear

pass: pop cx ;
LOOP wait_for_key ;

down: ;没输空格,ESC,

也没输正确的时候,只向下移一格,用循环再向下移动
mov ah, 0ah ; 在当前光标位置写空格
mov al, " "
mov bh, 00h
mov cx, 01h
int 10h ;

inc dh ;
mov ah, 02h ; 改变光标位置
mov bh, 00h
int 10h

mov ah, 0ah ; 在当前光标位置写字母
mov al, [di]
mov bh, 00h
mov cx, 01h
int 10h ;

pop cx
loop nextrow ; 下一行
JMP LETTER_OVER
TO_KAISHI: JMP KAISHI

letter_over: ;下落21行后还是没打中(即字母消失),也没按ESC
mov ah, 0ah
mov al, " "
mov bh, 00h
mov cx, 01h
int 10h ;

inc dh ;
mov ah, 02h
mov bh, 00h
int 10h ;

mov ah, 0ah
mov al, " " ;
mov bh, 00h
mov cx, 01h
int 10h

jmp next_letter

disappear: ; 击中字母后输出空格
pop cx
pop cx
INC RIGHT ;记录正确输入的字母个数
ADD SCORE,CX ;记录分数,打的时间越短则得分越高,分数以行数记

mov ah, 0ah ;
mov al, " " ;
mov bh, 00h
mov cx, 01h
int 10h
JMP NEXT_LETTER
SHOWSCORE:
CLS
MENU 08D,14D,MESS2
MOV AX,SCORE ;
MOV DX,0FFFFH
CALL WRITEDEC
MENU 09D,14D,MESS3
MOV AX,NUM
PUSH AX
MOV DX,0FFFFH
POP AX
CALL WRITEDEC

MENU 10D,14D,MESS4
MOV AX,RIGHT
MOV DX,0FFFFH
CALL WRITEDEC
MENU 11D,14D,MESS5
MOV AH,07H
INT 21H
JMP TO_KAISHI ;

next_letter:mov ah, 02h ;
mov bh, 00h ;
mov dh, 01h
mov dl, present_position ;
int 10h ;

mov al, [di] ; 出现下一个新字母的算法
add al, 7 ;
cmp al, 7ah
jna next_letter1
sub al, 26
next_letter1:mov ah, 0ah
mov bh, 00h
mov cx, 01h
int 10h ;

mov [di], al
PUSH BX
MOV BL,ET
SUB BL,B
CMP BL,10 ;当玩游戏时间到了10秒,不真正为10秒,因为运行程序也需要时间
JAE TO_SHOWSCORE
POP BX
jmp start_game
TO_SHOWSCORE: CMP SCORE,150 ;且分数未达到规定的要求,则自动退出游戏
JAE TO_START
JMP SHOWSCORE
TO_START:
JMP START_GAME
;名称:LEVEL
;选择难度
;入口参数AL
;出口参数AX
;影响寄存器AX
LEVEL PROC NEAR
PUSH CX
PUSH DX
HERE:
MENU 08D,22D,EASY
MENU 09D,22D,NORMAL
MENU 10D,22D,HARD
MENU 11D,11D,FL
MOV AH,07H
INT 21H
CMP AL,'E'
JE LA
CMP AL,'N'
JE LB
CMP AL,'H'
JE LC
JMP HERE
LA: MOV AX,9000H
JMP LD
LB: MOV AX,6000H
JMP LD
LC: MOV AX,3000H
LD: POP DX
POP CX
RET
LEVEL ENDP


main endp
code ends
end start




相关文档
最新文档