📄 推箱子.asm
字号:
call draw
jmp near ptr waiting
ryfredr:
sub cx,100
mov al,5
call draw
add cx,50
mov al,9
call draw
mov [di],cx
add cx,50
mov al,2
call draw
jmp near ptr waiting
yarn:
add cx,100
int 10h ;读像素
cmp al,5 ;更前方是否为红
je ryfredn
sub cx,100 ;更前方为黑
mov al,0
call draw
add cx,50
mov al,9
call draw
mov [di],cx
add cx,50
mov al,14
call draw
jmp near ptr waiting
ryfredn:
sub cx,100
mov al,0
call draw
add cx,50
mov al,9
call draw
mov [di],cx
add cx,50
mov al,2
call draw
jmp near ptr waiting
;----------------------------------------------------------
;------------------------------------------------------------------------------------------------------------
upwards:
mov ah,0dh ;读像素
mov bh,0
mov dx,[si]
mov cx,[di]
sub dx,50
int 10h
;判断所在是否为红
add dx,50
cmp cx,151
je isredu
cmp cx,51
jne uredn
cmp dx,201
jne uredn
jmp uredr
isredu:
cmp dx,51
je uredr
cmp dx,101
je uredr
jmp uredn
uredn:
sub dx,50
cmp al,0 ;可行?
jne upcon ;不黑
add dx,50
mov al,0
call draw
mov al,9
sub dx,50
call draw
mov [si],dx ;重记worker位置
jmp near ptr waiting ;等待
uredr:
sub dx,50
cmp al,0 ;可行?
jne upcon ;不黑
add dx,50
mov al,5
call draw
mov al,9
sub dx,50
call draw
mov [si],dx ;重记worker位置
jmp near ptr waiting ;等待
;--------------------------------------------
upcon:
cmp al,5;前方是否红
je redaheadup;是红
cmp al,2;前方是否绿
je greenaheadup;是绿
cmp al,15;前方是否白
je near ptr waiting ;撞墙
cmp al,14;前方是否黄(箱子)
je yellowaheadup
;--------------------------------------------
redaheadup:
add dx,50
;判断所在是否为红
cmp cx,151
je rucj
cmp cx,51
jne raun
cmp dx,201
jne raun
jmp raur
rucj:
cmp dx,51
je raur
cmp dx,101
je raur
jmp raun
raur:
mov al,5 ;自己所在为红
call draw
sub dx,50
mov al,9
call draw
mov [si],dx ;重记worker位置
jmp near ptr waiting
raun:
mov al,0 ;自己所在非红
call draw
sub dx,50
mov al,9
call draw
mov [si],dx
jmp near ptr waiting
;--------------------------------------------
greenaheadup:
sub dx,50
int 10h ;读像素
cmp al,15 ;更前方是否为白(箱子撞墙)
je near ptr waiting
cmp al,14 ;更前方是否为黄(箱子撞箱子)
je near ptr waiting
cmp al,2 ;更前方是否为绿
je near ptr waiting
add dx,100
;判断所在是否为红
cmp cx,151
je gucj
cmp cx,51
jne gaun
cmp dx,201
jne gaun
jmp gaur
gucj:
cmp dx,51
je gaur
cmp dx,101
je gaur
jmp gaun
gaur:
sub dx,100
int 10h ;读像素
cmp al,5 ;更前方是否为红
je ugfredr
add dx,100 ;更前方为黑
mov al,5
call draw
sub dx,50
mov al,9
call draw
mov [si],dx
sub dx,50
mov al,14
call draw
jmp near ptr waiting
ugfredr:
add dx,100
mov al,5
call draw
sub dx,50
mov al,9
call draw
mov [si],dx
sub dx,50
mov al,2
call draw
jmp near ptr waiting
gaun:
sub dx,100
int 10h ;读像素
cmp al,5 ;更前方是否为红
je ugfredn
add dx,100 ;更前方为黑
mov al,0
call draw
sub dx,50
mov al,9
call draw
mov [si],dx
sub dx,50
mov al,14
call draw
jmp near ptr waiting
ugfredn:
add dx,100
mov al,0
call draw
sub dx,50
mov al,9
call draw
mov [si],dx
sub dx,50
mov al,2
call draw
jmp near ptr waiting
;----------------------------------------------------------
yellowaheadup:
sub dx,50
int 10h ;读像素
cmp al,15 ;更前方是否为白(箱子撞墙)
je near ptr waiting
cmp al,14 ;更前方是否为黄(箱子撞箱子)
je near ptr waiting
cmp al,2 ;更前方是否为绿
je near ptr waiting
add dx,100
;判断所在是否为红
cmp cx,151
je yucj
cmp cx,51
jne yaun
cmp dx,201
jne yaun
jmp yaur
yucj:
cmp dx,51
je yaur
cmp dx,101
je yaur
jmp yaun
yaur:
sub dx,100
int 10h ;读像素
cmp al,5 ;更前方是否为红
je uyfredr
add dx,100 ;更前方为黑
mov al,5
call draw
sub dx,50
mov al,9
call draw
mov [si],dx
sub dx,50
mov al,14
call draw
jmp near ptr waiting
uyfredr:
add dx,100
mov al,5
call draw
sub dx,50
mov al,9
call draw
mov [si],dx
sub dx,50
mov al,2
call draw
jmp near ptr waiting
yaun:
sub dx,100
int 10h ;读像素
cmp al,5 ;更前方是否为红
je uyfredn
add dx,100 ;更前方为黑
mov al,0
call draw
sub dx,50
mov al,9
call draw
mov [si],dx
sub dx,50
mov al,14
call draw
jmp near ptr waiting
uyfredn:
add dx,100
mov al,0
call draw
sub dx,50
mov al,9
call draw
mov [si],dx
sub dx,50
mov al,2
call draw
jmp near ptr waiting
;----------------------------------------------------------
;------------------------------------------------------------------------------------------------------------
dnwards:
mov ah,0dh ;读像素
mov bh,0
mov dx,[si]
mov cx,[di]
add dx,50
int 10h
;判断所在是否为红
sub dx,50
cmp cx,151
je isredd
cmp cx,51
jne dredn
cmp dx,201
jne dredn
jmp dredr
isredd:
cmp dx,51
je dredr
cmp dx,101
je dredr
jmp dredn
dredn:
add dx,50
cmp al,0 ;可行?
jne dncon ;不黑
sub dx,50
mov al,0
call draw
mov al,9
add dx,50
call draw
mov [si],dx ;重记worker位置
jmp near ptr waiting ;等待
dredr:
add dx,50
cmp al,0 ;可行?
jne dncon ;不黑
sub dx,50
mov al,5
call draw
mov al,9
add dx,50
call draw
mov [si],dx ;重记worker位置
jmp near ptr waiting ;等待
;--------------------------------------------
dncon:
cmp al,5;前方是否红
je redaheaddn;是红
cmp al,2;前方是否绿
je greenaheaddn;是绿
cmp al,15;前方是否白
je near ptr waiting ;撞墙
cmp al,14;前方是否黄(箱子)
je yellowaheaddn
;--------------------------------------------
redaheaddn:
sub dx,50
;判断所在是否为红
cmp cx,151
je rdcj
cmp cx,51
jne radn
cmp dx,201
jne radn
jmp radr
rdcj:
cmp dx,51
je radr
cmp dx,101
je radr
jmp radn
radr:
mov al,5 ;自己所在为红
call draw
add dx,50
mov al,9
call draw
mov [si],dx ;重记worker位置
jmp near ptr waiting
radn:
mov al,0 ;自己所在非红
call draw
add dx,50
mov al,9
call draw
mov [si],dx
jmp near ptr waiting
;--------------------------------------------
greenaheaddn:
add dx,50
int 10h ;读像素
cmp al,15 ;更前方是否为白(箱子撞墙)
je near ptr waiting
cmp al,14 ;更前方是否为黄(箱子撞箱子)
je near ptr waiting
cmp al,2 ;更前方是否为绿
je near ptr waiting
sub dx,100
;判断所在是否为红
cmp cx,151
je gdcj
cmp cx,51
jne gadn
cmp dx,201
jne gadn
jmp gadr
gdcj:
cmp dx,51
je gadr
cmp dx,101
je gadr
jmp gadn
gadr:
add dx,100
int 10h ;读像素
cmp al,5 ;更前方是否为红
je dgfredr
sub dx,100 ;更前方为黑
mov al,5
call draw
add dx,50
mov al,9
call draw
mov [si],dx
add dx,50
mov al,14
call draw
jmp near ptr waiting
dgfredr:
sub dx,100
mov al,5
call draw
add dx,50
mov al,9
call draw
mov [si],dx
add dx,50
mov al,2
call draw
jmp near ptr waiting
gadn:
add dx,100
int 10h ;读像素
cmp al,5 ;更前方是否为红
je dgfredn
sub dx,100 ;更前方为黑
mov al,0
call draw
add dx,50
mov al,9
call draw
mov [si],dx
add dx,50
mov al,14
call draw
jmp near ptr waiting
dgfredn:
sub dx,100
mov al,0
call draw
add dx,50
mov al,9
call draw
mov [si],dx
add dx,50
mov al,2
call draw
jmp near ptr waiting
;----------------------------------------------------------
yellowaheaddn:
add dx,50
int 10h ;读像素
cmp al,15 ;更前方是否为白(箱子撞墙)
je near ptr waiting
cmp al,14 ;更前方是否为黄(箱子撞箱子)
je near ptr waiting
cmp al,2 ;更前方是否为绿
je near ptr waiting
sub dx,100
;判断所在是否为红
cmp cx,151
je ydcj
cmp cx,51
jne yadn
cmp dx,201
jne yadn
jmp yadr
ydcj:
cmp dx,51
je yadr
cmp dx,101
je yadr
jmp yadn
yadr:
add dx,100
int 10h ;读像素
cmp al,5 ;更前方是否为红
je dyfredr
sub dx,100 ;更前方为黑
mov al,5
call draw
add dx,50
mov al,9
call draw
mov [si],dx
add dx,50
mov al,14
call draw
jmp near ptr waiting
dyfredr:
sub dx,100
mov al,5
call draw
add dx,50
mov al,9
call draw
mov [si],dx
add dx,50
mov al,2
call draw
jmp near ptr waiting
yadn:
add dx,100
int 10h ;读像素
cmp al,5 ;更前方是否为红
je dyfredn
sub dx,100 ;更前方为黑
mov al,0
call draw
add dx,50
mov al,9
call draw
mov [si],dx
add dx,50
mov al,14
call draw
jmp near ptr waiting
dyfredn:
sub dx,100
mov al,0
call draw
add dx,50
mov al,9
call draw
mov [si],dx
add dx,50
mov al,2
call draw
jmp near ptr waiting
;--------------------------------------------------------------------------------------------------
return:
call screen_init
mov si,offset workerx
mov dx,51
mov di,offset workery
mov cx,201
mov [si],dx
mov [di],cx
mov bx,offset warning
mov [bx],200
mov bx,0
jmp near ptr waiting
;--------------------------------------------------------------------------------------
die:
pop cx
push di
mov si,offset gameover
mov di,offset gameover_ch
call gover
pop di
pop si
call waitf
jmp quit1
;--------------------------------------------------------------------------------------
win:
push si
push di
mov si,offset gamewin
mov di,offset gamewin_ch
call gover
pop di
pop si
call waitf
;--------------------------------------------------------------------------------------
quit1:
pop di
pop si
pop dx
pop cx
pop bx
pop ax
ret
play endp
;===========================================================================
;威胁子程序 thre
;--------------------------------
thre proc ;far
push ax
push bx
push cx
push dx
push si
mov ah,0ch
mov al,13
mov bh,0
mov si,offset warning
mov dx,400
mov cx,[si]
int 10h
inc cx
mov [si],cx
pop si
pop dx
pop cx
pop bx
pop ax
ret
thre endp
;======================================
;清屏子程序clear_screen
;======================================
clear_screen proc ;far
;save registers
push ax
push bx
push cx
push dx
;clear screen
mov ah,6 ;to scroll up screen
mov al,0 ;blank screen
mov bh,7 ;blank line
mov ch,0 ;upper left row
mov cl,0 ;upper left column
mov dh,24 ;lower right row
mov dh,79 ;lower right column
int 10h ;call video BIOS
;locate cursor
mov dx,0
mov ah,2 ;to locate cursor
int 10h
;restore registers
pop dx
pop cx
pop bx
pop ax
ret
clear_screen endp
;=================================================================================
;结束子程序 gover
;-------------------------------
gover proc ;far
push ax
push bx
push cx
push dx
push si
push di
mov ah,0
mov al,3
int 10h
call clear_screen
show_o:
mov ah,2
mov dl,[si]
inc si
mov dh,[si]
inc si
mov bh,0
int 10h
mov ah,9
mov al,[di]
cmp al,'!'
je ov
mov bl,1110b
mov cx,1
int 10h
inc di
jmp show_o
ov: pop di
pop si
pop dx
pop cx
pop bx
pop ax
ret
gover endp
;================================================================================
;WAITF延迟子程序
;--------------------------------------------
waitf proc far
push ax
waitf1: in al,61h
and al,10h
cmp al,ah
je waitf1
mov ah,al
loop waitf1
pop ax
ret
waitf endp
;====================================================================
end main
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -