📄 typing.asm
字号:
;菜单显示宏定义
menu macro op1,op2,op3
mov ah,02h
mov bh,00h
mov dh,op1
mov dl,op2
int 10h
mov ah,09h
lea dx,op3
int 21h
endm
;清屏宏定义
clear_screen macro op1,op2,op3,op4
mov ah,06h
mov al,00h
mov bh,07h
mov ch,op1
mov cl,op2
mov dh,op3
mov dl,op4
int 10h
mov ah,02h
mov bh,00h
mov dh,00h
mov dl,00h
int 10h
endm
;数据段定义:
data segment
ZK db "(:WELCOME TO MY TYPING GAME:)$"
meg db "Press Enter key to continue~$"
meg2 db "Press Space key to pause~$"
meg3 db "Press Esc key to the main menu~$"
meg4 db "Press letter 'w' to exit~$"
meg5 db "please select the speed:$"
meg6 db "1.slow$"
meg7 db "2.fast$"
meg8 db "life: 5$"
meg9 db "GAME OVER$"
meg10 db "Bingo: 0$"
meg11 db "You have only 5 lifes.$"
meg12 db "The life will lost if you don't hit the word.$"
meg13 db "When the life goes 0 , you will die!$"
speed dw 600d
nandu dw 0d
slowsd dw 3000d ;快速模式的速度值
fastsd dw 800d ;慢速模式的速度值
life db "5" ;初始生命值
hittimel db "0$" ;积分值的个位
hittimeh db "0$" ;积分值的十位
letters db "jwmilzoeucgpravskntxhdyqfb"
db "iytpkwnxlsvxrmofzhgaebudjq"
db "nwimzoexrphysfqtvdcgljukda"
letters_bak db "jwmilzoeucgpravskntxhdyqfb"
db "iytpkwnxlsvxrmofzhgaebudjq"
db "nwimzoexrphysfqtvdcgljukda"
letter_counter db 0
position_flag db 78 dup(0)
present_position db 1 ;当前字母所在列
data ends
;堆栈段定义:
stack segment para stack 'stack'
db 64 dup(0)
stack ends
;代码段:
code segment
main proc far
assume cs:code,ds:data,ss:stack
start: mov ax,data
mov ds,ax
mov letter_counter,00h
mov present_position,1
lea si,position_flag
mov ah,00h
mov cx,00h
init_postion_flag:
mov [si],ah
inc si
inc cx
cmp cx,78d
jne init_postion_flag
lea di,letters
lea si,letters_bak
mov cx,00h
init_letters:
mov ah,[si]
mov [di],ah
inc si
inc di
inc cx
cmp cx,78d
jne init_letters
mov cx,00h
mov ah,01h
or ch,00010000b ;消除字符的闪烁
int 10h
clear_screen 00d,00d,24d,79d
clear_screen 00d,00d,24d,79d
menu 07d,22d,ZK ;显示菜单
menu 09d,22d,meg
menu 11d,22d,meg2
menu 13d,22d,meg3
menu 15d,22d,meg4
put: mov ah,02h
mov bh,00h
mov dh,55d
mov dl,35d
int 10h
mov ah,01h
int 21h
cmp al,0dh ;输入回车进入速度选单
je selsudu
cmp al,77h ;输入w游戏结束
jne put
exit: mov ah,02h
mov bh,00h
mov dh,55d
mov dl,35d
int 10h
mov ah,4ch
int 21h
selsudu:clear_screen 00d,00d,24d,79d ;选择速度菜单
menu 13d,18d,meg5
menu 15d,19d,meg6
menu 17d,19d,meg7
menu 06d,18d,meg11
menu 08d,18d,meg12
menu 10d,18d,meg13
mov ah,02h
mov bh,00h
mov dh,52d
mov dl,33d
int 10h
mov ah,01h
int 21h
cmp al,"1"
je slow
cmp al,"2"
je fast
jmp selsudu
slow: mov dx,slowsd ;将慢速赋给nandu
mov nandu,dx
jmp speed3
fast: mov dx,fastsd ;将快速赋给nandu
mov nandu,dx
jmp speed3
speed3: mov ax,speed+12
mov speed,ax
jmp begin
begin: clear_screen 01d,01d,23d,78d ;清屏
clear_screen 01d,01d,23d,78d
menu 24d,67d,meg8 ;显示生命和积分
menu 24d,55d,meg10
mov ah,02h
mov bh,00h
mov dh,00h
mov dl,01h
int 10h
mov cx,00h
lea si,letters
nextletter:
mov ah,02h ;显示字母
mov dl,[si]
int 21h
inc si
inc cx
cmp cx,78d
je nextcycle
jmp nextletter
from_front:
sub present_position,78d
jmp gobackto_si
find_zero:
cmp letter_counter,78d
je recycle
cmp present_position,78d
je from_one
mov ah,00h
nextsi: add present_position,01h
inc si
cmp [si],ah
je gobackto_di
cmp present_position,78d
je from_one
jmp nextsi
from_one:mov present_position,01h
jmp gobackto_si
recycle:mov letter_counter,00h
mov present_position,01d
lea si,position_flag
mov cx,00h
mov ah,00h
clearsi: mov [si],ah
inc cx
cmp cx,78d
je nextcycle
inc si
jmp clearsi
nextcycle:
lea di,letters
lea si,position_flag
add present_position,31d
cmp present_position,78
ja from_front
gobackto_si:
add si,word ptr present_position
dec si
mov ah,[si]
cmp ah,01h
je find_zero
gobackto_di:
mov ah,01h
mov [si],ah
add di,word ptr present_position
dec di
mov dl,present_position
mov ah,02h
mov bh,00h
mov dh,00h
int 10h
mov cx,00h
nextrow: push cx ;每个字母的循环
mov cx,00h
out_cycle: ;字母下落一拍的循环
push cx
mov cx,00h
in_cycle: ;一拍中的循环
add cx,01h ; 延迟
cmp cx,nandu
jne in_cycle
push dx
mov ah,06h ;从键盘输入字符
mov dl,0ffh
int 21h
pop dx
jz pass
cmp al,1bh ;输入ESC,返回主菜单
je to_start1
cmp al," " ;输入SPACE,游戏暂停
je pause
cmp al,[di] ;输入字母正确,字母消失
je disappear
pass: pop cx
inc cx
cmp cx,speed
je print
jmp out_cycle
pause: push dx ;暂停
mov ah,06h
mov dl,0ffh
int 21h
pop dx
cmp al," "
jne pause
jmp pass
to_start1: ;返回主菜单
mov bl,"0"
mov hittimel,bl
mov hittimeh,bl
mov bl,"5"
mov life,bl
jmp start
print:
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
inc cx
cmp cx,23d
je print_next_letter
jmp nextrow ;下一行
disappear: ;击中字母后输出空格
pop cx
pop cx
mov ah,0ah
mov al," "
mov bh,00h
mov cx,01h
int 10h
mov bl,hittimel ;显示积分
cmp bl,"9"
je jinwei
inc bl
mov hittimel,bl
menu 24d,63d,hittimel
jmp hit
jinwei: ;积分十位的显示
mov bl,hittimeh
inc bl
mov hittimeh,bl
mov hittimel,"0"
menu 24d,62d,hittimeh
menu 24d,63d,hittimel
jmp hit
print_next_letter:
mov ah,0ah
mov al," "
mov bh,00h
mov cx,01h
int 10h
mov ah,02h ;显示生命值
mov bh,00h
mov dh,18h
mov dl,49h
int 10h
mov ah,0ah
mov bl,life
dec bl
mov life,bl
mov al,bl
mov bh,00h
mov cx,01h
int 10h
cmp bl,"0" ;生命值为0游戏结束
je gameover
jmp hit
gameover:
menu 9d,23d,meg9
menu 13d,23d,meg3
mov ah,06h
mov dl,0ffh
int 21h
cmp al,1bh
je to_start1
jmp gameover
hit: mov ah,02h
mov bh,00h
mov dh,00h
mov dl,present_position
int 10h
mov al,[di] ; 出现下一个新字母的算法
add al,7
cmp al,7ah
ja convey_letter
mov ah,0ah
mov bh,00h
mov cx,01h
int 10h
mov [di],al
add letter_counter,01h
jmp nextcycle
convey_letter:
sub al,7ah
add al,61h
mov ah,0ah
mov bh,00h
mov cx,01h
int 10h
mov [di],al
add letter_counter,01h
jmp nextcycle
clear_screen 01,01,23,78
mov ah,02h
mov bh,00h
mov dh,11d
mov dl,20d
int 10h
inc dh
inc dh
mov ah,02h
mov bh,00h
int 10h
notkey:
mov ah,07h
int 21h
cmp al,0dh
je to_start1
cmp al,1bh
je over
jmp notkey
to_start:
clear_screen 00,00,24,79
jmp start
over: clear_screen 01,01,23,78
mov ah,02h
mov bh,00h
mov dh,11d
mov dl,15h
int 10h
mov ah,02h
mov bh,00h
mov dh,13d
mov dl,15h
int 10h
mov ah,07h
int 21h
mov ah,07h
int 21h
clear_screen 00,00,24,79
mov ax,4c00h
int 21h
main endp
code ends
end start
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -