📄 ss.asm
字号:
assume cs:code,ds:code,ss:stack
stack segment
dw 32 dup (0)
stack ends
code segment
start: mov ax,cs
mov ds,ax
mov ax,stack
mov ss,ax
mov sp,64
;------------------------------------------------------------
mov ax,offset setstable ;初始化setscreen中的命令向量表
mov si,ax ;若不初始化,下面就无法调用cls
;---------------------------- ;其实,只需要初始化1〉setsub1
mov ax,offset setsub1 ;1〉子程序setsub1
mov [si+0],ax
mov ax,offset setsub2 ;2〉子程序setsub2
mov [si+2],ax
mov ax,offset setsub3 ;3〉子程序setsub3
mov [si+4],ax
mov ax,offset setsub4 ;4〉子程序setsub4
mov [si+6],ax
;------------------------------------------------------------
fossetups:call cls ;清屏
mov ah,2 ;把光标挪走
mov bh,1 ;光标所在页数
int 10h
;------------------------------------------------------------
mov dh,2 ;显示gamestart界面
mov dl,37
mov si,offset gametxt1
call showstr
mov dh,3
mov dl,35
mov si,offset gametxt2
call showstr
call delay
mov dh,5
mov dl,25
mov si,offset gametxt3
call showstr
mov dh,6
mov dl,25
mov si,offset gametxt4
call showstr
mov dh,7
mov dl,25
mov si,offset gametxt5
call showstr
mov dh,8
mov dl,25
mov si,offset gametxt6
call showstr
mov dh,9
mov dl,25
mov si,offset gametxt7
call showstr
mov dh,10
mov dl,25
mov si,offset gametxt8
call showstr
call delay
mov dh,13
mov dl,25
mov si,offset gametxt9
call showstr
call delay
mov dh,14
mov dl,22
mov si,offset gametxt10
call showstr
call delay
mov dh,18
mov dl,34
mov si,offset gametxt12
call showstr
call delay
mov dh,21
mov dl,34
mov si,offset gametxt11
call showstr
mov dh,21 ;设置光标
mov dl,50
mov ah,2
mov bh,0
int 10h
;start界面显示完毕
;--------------------------------------------------
loop1: mov ah,0 ;判断是否开始游戏
int 16h
cmp ah,01h ;esc键
je gameret
cmp ah,1ch ;enter键
je gamego
cmp al,'y'
je gamego
cmp al,'n'
je gameret
jmp short loop1
gameret:mov ax,4c00h
int 21h
;-------------------------------------------------
gamego: mov r1step,0 ;游戏开始,进行初始化
mov r1flower,0
mov r1money,0
mov r1score,500
mov r2step,0
mov r2flower,0
mov r2money,0
mov r2score,500
call cls ;清屏
mov ah,2 ;setscreen的2号功能
mov al,7 ;设置前景颜色为白色
call setscreen
mov dh,0
mov dl,37
mov si,offset gametxt1
call showstr
mov dh,1
mov dl,35
mov si,offset gametxt2
call showstr
call delay
;------------------------------------------------
mov si,offset puzzletxt0
mov dh,2
mov dl,18
call showstr
mov si,offset puzzletxt1 ;以下开始显示迷宫图
mov dh,3
mov dl,18
call showstr
mov si,offset puzzletxt2
mov dh,4
mov dl,18
call showstr
mov si,offset puzzletxt3
mov dh,5
mov dl,18
call showstr
mov si,offset puzzletxt4
mov dh,6
mov dl,18
call showstr
mov si,offset puzzletxt5
mov dh,7
mov dl,18
call showstr
mov si,offset puzzletxt6
mov dh,8
mov dl,18
call showstr
mov si,offset puzzletxt7
mov dh,9
mov dl,18
call showstr
mov si,offset puzzletxt8
mov dh,10
mov dl,18
call showstr
mov si,offset puzzletxt9
mov dh,11
mov dl,18
call showstr
mov si,offset puzzletxt10
mov dh,12
mov dl,18
call showstr
mov si,offset puzzletxt11
mov dh,13
mov dl,18
call showstr
mov si,offset puzzletxt12
mov dh,14
mov dl,18
call showstr
mov si,offset puzzletxt13
mov dh,15
mov dl,18
call showstr
mov si,offset puzzletxt14
mov dh,16
mov dl,18
call showstr
mov si,offset puzzletxt15
mov dh,17
mov dl,18
call showstr
mov si,offset puzzletxt16
mov dh,18
mov dl,18
call showstr
mov si,offset puzzletxt17
mov dh,19
mov dl,18
call showstr
mov si,offset puzzletxt18
mov dh,20
mov dl,18
call showstr
mov si,offset puzzletxt19
mov dh,21
mov dl,18
call showstr
mov si,offset puzzletxt20
mov dh,23
mov dl,20
call showstr ;迷宫显示完毕
;------------------------------------------------
mov color,2
mov ah,2 ;显示出口
mov bh,0
mov dh,20
mov dl,63
int 10h
mov al,1ah
call showchar
mov ah,2 ;显示入口
mov bh,0
mov dh,4
mov dl,17
int 10h
mov al,1ah
call showchar
mov ah,2 ;显示角色1
mov bh,0
mov dh,4
mov dl,19
mov role1,dx ;保存人物1的当前行列值
int 10h
mov al,1 ;人物1的头像
call showchar
mov color,4
mov ah,2 ;显示角色2
mov bh,0
mov dh,4
mov dl,21
mov role2,dx ;保存人物2的当前行列值
int 10h
mov al,2 ;人物2的头像
call showchar
;------------------------------------------
loop2: mov ah,0 ;接受一个字符
int 16h
cmp ah,01 ;esc键
je gamefail
cmp ah,48h ;人物1
je r1up
cmp ah,4bh ;人物1
je r1left
cmp ah,4dh ;人物1
je r1right
cmp ah,50h ;人物1
je r1down
cmp al,'w' ;人物2
je r2up
cmp al,'a' ;人物2
je r2left
cmp al,'d' ;人物2
je r2right
cmp al,'s' ;人物2
je r2down
jmp short loop2
;------------------------------------
gamefail:call cls ;游戏失败
mov ah,2 ;设置前景颜色为白色
mov al,7
call setscreen
mov rolehead,0 ;判断谁输谁赢时使用
mov si,offset gametxt13
mov dh,1
mov dl,26
call showstr
call gameover
;------------------------------------
r1up: call role1go
call goup
call role1ok
jmp short loop2
r1left: call role1go
call goleft
call role1ok
jmp short loop2
r1right:call role1go
call goright
call role1ok
jmp short loop2
r1down: call role1go
call godown
call role1ok
jmp short loop2
;------------------------------------
r2up: call role2go
call goup
call role2ok
jmp near ptr loop2
r2left: call role2go
call goleft
call role2ok
jmp near ptr loop2
r2right:call role2go
call goright
call role2ok
jmp near ptr loop2
r2down: call role2go
call godown
call role2ok
jmp near ptr loop2
;--------------------------------------
role1go:mov rolehead,1 ;将当前人物转换成角色1
mov color,2
mov ax,r1flower
mov flower,ax
mov ax,r1money
mov money,ax
mov ax,r1step
mov step,ax
mov ax,r1score
mov score,ax
mov dx,role1
mov ah,2 ;将光标定位到角色1
mov bh,0
int 10h
call addr ;角色1的当前位置es:di
ret
role1ok:mov ax,flower ;角色1走完一步
mov r1flower,ax
mov ax,money
mov r1money,ax
mov ax,step
mov r1step,ax
mov ax,score
mov r1score,ax
mov role1,dx
cmp dx,143eh ;判断是否走完迷宫
je gameok
ret
role2go:mov rolehead,2 ;将当前人物转换成角色2
mov color,4
mov ax,r2flower
mov flower,ax
mov ax,r2money
mov money,ax
mov ax,r2step
mov step,ax
mov ax,r2score
mov score,ax
mov dx,role2
mov ah,2 ;将光标定位到角色2
mov bh,0
int 10h
call addr ;角色2的当前位置es:di
ret
role2ok:mov ax,flower ;角色2走完一步
mov r2flower,ax
mov ax,money
mov r2money,ax
mov ax,step
mov r2step,ax
mov ax,score
mov r2score,ax
mov role2,dx
cmp dx,143eh ;判断是否走完迷宫
je gameok
ret
;------------------------------------
gameok: call cls ;迷宫走完后,清屏
mov ah,2 ;设置前景颜色为白色
mov al,7
call setscreen
mov si,offset gametxt14
mov dh,1
mov dl,26
call showstr
mov si,offset gametxt22
mov dh,3
mov dl,35
call showstr
mov ah,2 ;显示winner头像
mov bh,0
mov dh,3
mov dl,43
int 10h
mov al,rolehead
call showchar
call gameover
;--------------------------------------
goup: cmp byte ptr es:[di-160],'-'
je goupret
cmp byte ptr es:[di-160],'|'
je goupret
cmp byte ptr es:[di-160],'*'
jne goup1
inc flower
add score,100
goup1: cmp byte ptr es:[di-160],'$'
jne goup2
inc money
add score,50
goup2: mov al,0f9h
call showchar
dec dh
mov ah,2
mov bh,0
int 10h
mov al,rolehead ;显示当前角色头像
call showchar
inc step
dec score
goupret:ret
;-------------------------------------------
goleft: cmp byte ptr es:[di-2],'|'
je goleftret
cmp byte ptr es:[di-2],'-'
je goleftret
cmp byte ptr es:[di-2],1ah
je goleftret
cmp byte ptr es:[di-2],'*'
jne goleft1
inc flower
add score,100
goleft1:cmp byte ptr es:[di-2],'$'
jne goleft2
inc money
add score,50
goleft2:mov al,0f9h
call showchar
dec dl
mov ah,2
mov bh,0
int 10h
mov al,rolehead ;显示当前角色头像
call showchar
inc step
dec score
goleftret:ret
;--------------------------------------------
goright:cmp byte ptr es:[di+2],'|'
je gorightret
cmp byte ptr es:[di+2],'-'
je gorightret
cmp byte ptr es:[di+2],'*'
jne goright1
inc flower
add score,100
goright1:cmp byte ptr es:[di+2],'$'
jne goright2
inc money
add score,50
goright2:mov al,0f9h
call showchar
inc dl
mov ah,2
mov bh,0
int 10h
mov al,rolehead ;显示当前角色头像
call showchar
inc step
dec score
gorightret:ret
;-------------------------------------------
godown: cmp byte ptr es:[di+160],'-'
je godownret
cmp byte ptr es:[di+160],'|'
je godownret
cmp byte ptr es:[di+160],'*'
jne godown1
inc flower
add score,100
godown1:cmp byte ptr es:[di+160],'$'
jne godown2
inc money
add score,50
godown2:mov al,0f9h
call showchar
inc dh
mov ah,2
mov bh,0
int 10h
mov al,rolehead ;显示当前角色头像
call showchar
inc step
dec score
godownret:ret
;--------------------------------------------
gameover:mov ah,2 ;把光标挪走
mov bh,1 ;光标所在页数
int 10h
;--------------------------------------------
;显示角色1的结果
mov si,offset gametxt23
mov dh,5
mov dl,16
call showstr
mov ah,2 ;显示role1头像
mov bh,0
mov dh,5
mov dl,23
int 10h
mov al,1
mov color,2
call showchar
mov si,offset gametxt15
mov dh,7
mov dl,10
call showstr
call delay
mov si,offset gametxt20 ;money
mov ax,r1money
call dtoc
mov dh,9
mov dl,16
call showstr
mov si,offset gametxt16
mov dh,9
mov dl,20
call showstr
call delay
mov si,offset gametxt20 ;flower
mov ax,r1flower
call dtoc
mov dh,11
mov dl,16
call showstr
mov si,offset gametxt17
mov dh,11
mov dl,20
call showstr
call delay
mov si,offset gametxt20 ;step
mov ax,r1step
call dtoc
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -