📄 cg.asm
字号:
;打字程序游戏
;按ENTER键开始
;按Esc键退出
data segment
play db '>> Press Enter to start <<'
repl db 'Press Enter to replay'
dazi db 'abcdefghijklmnopqrstuvwxyz'
outt db '>> Press Esc to quit <<'
endd db 'Game Over!'
divv db '============================================'
ppos db 1
db 0
spee dw 5000h
modd db 27
sco1 db 30h
sco2 db 30h
sco3 dB 30h
sco db 'SCORES:000 LIVES:9'
life db 39h
data ends
stack segment stack
db 20 dup(0)
stack ends
code segment
assume cs: code, ds: data,ss:stack
start: mov ax, data
mov ds, ax
call cls
mov ah,02h
mov bh,00h
mov dh,12
mov dl,8
int 10h
mov cx,26 ;进入游戏提示
lea si,play
lopp: mov ah,02h
mov dl,[si]
int 21h
inc si
loop lopp
call cang
input: mov ah, 07h ;输入命令字符
int 21h
cmp al, 0dh ;按回车键开始
je begin
jmp input
begin: mov sco1,30h
mov sco2, 30h
mov sco3 , 30h
call cls
mov ah,02h ;游戏结束提示
mov bh,00h
mov dh,23
mov dl,8
int 10h
mov cx,23
lea si,outt
over: mov ah,02h
mov dl,[si]
int 21h
inc si
loop over
mov ah,02h
mov bh,00h
mov dh,21
mov dl,4
int 10h
mov cx,31 ;得分
lea si,sco
lops: mov ah,02h
mov dl,[si]
int 21h
inc si
loop lops
mov ah,02h
mov bh,00h
mov dh,22
mov dl,1
int 10h
mov cx,38
lea si,divv
lop1: mov ah,02h
mov dl,[si]
int 21h
inc si
loop lop1
mov ah, 02h ;光标位置
mov bh, 00h
mov dh, 01h
mov dl, 07h
int 10h
mov cx, 26
lea si, dazi
first: mov ah, 02h ;显示字母
mov dl, [si]
int 21h
inc si
loop first
pgame: mov ah,2ch ;调用系统时间dl=1/100s
int 21h ;选择下落字母
mov al,dl
mov ah,0
div modd
cmp ah,7
jnae tz
mov dl,ah
jmp set
tz: add ah,26
mov dl,ah
set: mov ppos, dl
lea di, dazi
add di, word ptr ppos
call cang
mov ah,02h
mov dh,01h
mov dl,ppos
mov bh,00h
int 10h
mov cx, 19
nrow: push cx
mov cx, spee
waitt: push cx ;控制下落速度
mov cx,2000
delay: loop delay
push dx
mov ah, 06h ;从键盘输入字符
mov dl, 0ffh
int 21h
mov ah,07h
cmp al,1bh ;按Esc结束游戏
je quit
pop dx
cmp al,[di-7] ;输入正确字母消失
je disap
pop cx
loop waitt
mov ah, 0ah ;在当前位置写空格
mov al, 20h
mov bh, 00h
mov cx, 01h
int 10h
inc dh
mov ah, 02h ;改变光标位置
mov bh, 00h
int 10h
cmp dh,20
je space
mov ah, 0ah ;在当前位置写字母
mov al, [di-7]
mov bh, 00h
mov cx, 01h
int 10h
jmp agin
space: mov ah, 0ah ;在当前位置写空格
mov al, 20h
mov bh, 00h
mov cx, 01h
int 10h
push dx
mov ah,2
mov bh,0
mov dh,21
mov dl,34
int 10h
sub life,1
cmp life,30h
jl finish
mov ah,0ah
mov bh,0
mov al,life
mov cx,1
int 10h
pop dx
agin: pop cx
loop nrow
jmp next
beginn: mov life,39h
jmp begin
disap: jmp disapp
quit: mov ah,06h ;结束返回
mov al,00h
mov bh,07h
mov cx,00h
mov dh,27
mov dl,80
int 10h
mov ah,4ch
int 21h
finish: pop dx ;重置界面
pop cx
call cls
call cang
mov ah,02h
mov bh,00h
mov dh,10
mov dl,15
int 10h
mov cx,10
lea si,endd
lopen: mov ah,02h
mov dl,[si]
int 21h
inc si
loop lopen
mov ah,02h
mov bh,00h
mov dh,12
mov dl,9
int 10h
mov cx,21
lea si,repl
lopr: mov ah,02h
mov dl,[si]
int 21h
inc si
loop lopr
mov ah,02h
mov bh,00h
mov dh,14
mov dl,10
int 10h
mov cx,17
lea si,outt
lope: mov ah,02h
mov dl,[si+3]
int 21h
inc si
loop lope
replay: mov ah,07h
int 21h
cmp al,0dh
je beginn
cmp al,1bh
je quit
jmp replay
disapp: pop cx ;击中字母输出空格
pop cx
mov ah, 0ah
mov al, 20h
mov bh, 00h
mov cx, 01h
int 10h
call scor
next: mov ah, 02h
mov bh, 00h
mov dh, 01h
mov dl, ppos
int 10h
mov al,[di-7]
mov ah, 0ah
mov bh, 00h
mov cx, 01h
int 10h
jmp pgame
cang proc
mov ah,01h ;隐藏光标程序
mov ch,25
mov cl,0
int 10h
ret
cang endp
cls proc
mov ah,00h ;清屏子程序
mov al,01h
int 10h
mov ah,06h
mov al,00h
mov bh,70h
mov cx,00h
mov dh,26
mov dl,40
int 10h
ret
cls endp
scor proc ;计分子程
mov ah,2
mov bh,0
mov dh,21
mov dl,13
int 10h
add sco1,1
cmp sco1,39h
ja sco_2
mov ah,0ah
mov al,sco1
mov cx,1
mov bh,0
int 10h
jmp next
sco_2: sub sco1,10
mov ah,0ah
mov Bh,0
mov al,sco1
mov cx,1
int 10h
mov ah,2
mov Bh,0
mov dh,21
mov dl,12
int 10h
add sco2,1
cmp sco2,39h
ja sco_3
mov ah,0ah
mov bh,0
mov al,sco2
mov cx,1
int 10h
jmp next
sco_3: sub sco2,10
mov ah,0ah
mov bh,0
mov al,sco2
mov cx,1
int 10h
mov ah,2
mov bh,0
mov dh,21
mov dl,11
int 10h
add sco3,1
mov ah,0ah
mov bh,0
mov al,sco3
mov cx,1
int 10h
ret
scor endp
code ends
end start
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -