⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 推箱子.asm

📁 Double被关在了一个机关密室里
💻 ASM
📖 第 1 页 / 共 2 页
字号:
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;汇编专题实验--推箱子
;by 计算机51 宫亮亮 05055009
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

.model small
.data
;静态图块坐标
loc	dw 1,1,1,51,1,101,1,151,1,201,1,251,1,301
	dw 51,1,51,151,51,201,51,301
	dw 101,1,101,101,101,151,101,201,101,301
	dw 151,1,151,201,151,301
	dw 201,1,201,51,201,101,201,151,201,251,201,301
	dw 251,1,251,151,251,201,251,251
	dw 301,1,301,51,301,101,301,151	
;白色15,红色5,浅蓝9,黄色14,绿色2
color	db 7 dup(15)   
	db 15,5,9,15
	db 15,15,5,15,15
	db 15,14,15
	db 15,5,14,14,15,15
	db 4 dup(15)
	db 4 dup(15)
workerx dw 51
workery dw 201
set_win dw 51,151,101,151,201,151,255 ;目标位置坐标
warning dw 200						  ;步数槽开始纵坐标
gameover db 34,11,35,11,36,11,37,11,38,11,39,11,40,11,41,11,42,11,43,11,44,11
		 db 34,13,35,13,36,13,37,13,38,13,39,13,40,13,41,13,42,13,43,13,44,13
gameover_ch db ' ','Y','O','U',' ','L','O','S','E','&',' '
			db ' ','G','A','M','E',' ','O','V','E','R','!'
gamewin  db 34,11,35,11,36,11,37,11,38,11,39,11,40,11,41,11,42,11,43,11,44,11
		 db 34,12,35,12,36,12,37,12,38,12,39,12,40,12,41,12,42,12,43,12,44,12 
gamewin_ch db ' ','Y','O','U',' ',' ','W','I','N','&',' '
		   db ' ','G','A','M','E',' ','O','V','E','R','!'
str_quo db 'Q for quit,continue?','$'
.code

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;主程序
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
main    proc
	mov ax,@data
	mov ds,ax
		
	call screen_init   ;调用屏幕初始化子程序

	call play	       ;调用游戏操作子程序

	;询问是否退出
	lea dx,str_quo
	mov ah,9
    int 21h
       	
    mov ah,0
	int 16h
	cmp ah,10
	je  quit
        
quit: 
	
	mov si,offset gameover
	mov di,offset gameover_ch
	call gover    
	call waitf
	mov ax,4c00h
	int 21h
	ret
main    endp
;=================================================================
;调用屏幕初始化子程序
;screen_init 640*480
;---------------------------------------
screen_init     proc ;far
	push ax
	push bx
	push cx
	push dx
	
	mov ah,0
	mov al,12h   ;640*480,16色(EGA/VGA)
	int 10h
	
	mov si,offset loc
	mov di,offset color
	mov cx,39 ;共40个图块
back:	push cx
	
	mov dx,[si]
	add si,2
	mov cx,[si]
	add si,2
	mov al,[di]
	inc di
	call draw
	pop cx
	loop back
	
	;画个白边
	mov ah,0ch
	mov al,15
	mov bh,0
	mov dx,0
	mov cx,0
line1:
	int 10h
	inc dx
	cmp dx,330
	jne line1
line2:	
	inc cx
	int 10h
	cmp cx,330
	jne line2
line3:
	dec dx
	int 10h
	cmp dx,0
	jne line3
line4:
	dec cx
	int 10h
	cmp cx,0
	jne line4
;画步数槽的两端
    mov dx,400
    mov cx,199
    int 10h
	
	mov cx,401
	int 10h
	
	pop dx
	pop cx
	pop bx
	pop ax
	ret
screen_init	endp



;----------------------------------------------------------------------------------------------------------------
;画图块子程序 draw
;----------------------------------------------------------------------
draw	proc ;far
	
	push ax
	push bx
	push cx
	push dx
	push si
	push di
	
	
	
	push dx ;标记用
	mov ah,0ch
	;mov al,colour
	mov bh,0
	;mov dx,line
	;mov cx,row
	
	mov si,30  ;循环次数(30×30大小)
	mov di,30

pnt:	int 10h
	inc dx
	dec si
	cmp si,0
	jnz pnt
	mov si,30
	pop dx
	push dx
	inc cx
	dec di
	cmp di,0
	jnz pnt
	
	pop dx ;解除标记
	pop di
	pop si
	pop dx
	pop cx
	pop bx
	pop ax
	ret
draw	endp	
;===================================================================
;调用游戏操作子程序 play
;------------------------------------------------------
play	proc ;far
	push ax
	push bx
	push cx
	push dx
	push si
	push di
	mov si,offset workerx
	mov dx,[si]
	mov di,offset workery
	mov cx,[di]

waiting:	            ;等待指令
	push ax
	push bx
	push cx
	push dx
	push si
;--------------------------------	
	;判断是否胜利
	mov si,offset set_win
step1:
	mov dx,[si]
	cmp dx,255
	je  stepwin
	add si,2
	mov cx,[si]
	add si,2
	mov ah,0dh
	mov bh,0
	int 10h
	
	cmp al,2
	je step1
	jmp stepend
	
stepwin:	
	je  near ptr win
stepend:	
	pop si
	pop dx
	pop cx
	pop bx
	pop ax
	
;--------------------------------------------	
normal:	                       ;判断步数是否不足
	push si
	push cx
	mov si,offset warning
	mov cx,[si]
	cmp cx,400
	je  near ptr die		   ;步数不足,死亡
	pop  cx
	pop  si
	
	mov ah,0
	int 16h
	call thre				;调用威胁子程序,步数加一
;----------------------------------------------	
	cmp ah,4bh
	je  lfwards
	cmp ah,48h
	je  upwards
	cmp ah,50h
	je  dnwards
	cmp ah,4dh
	je  rtwards
	cmp ah,10h
	je  quit1
	cmp ah,13h
	je  return
	jmp near ptr waiting
;------------------------------------------------------------------------------------------------------------
lfwards:
	mov ah,0dh ;读像素
	mov bh,0
	mov dx,[si]
	mov cx,[di]
	sub cx,50
	int 10h
	
	
	;判断所在是否为红
	add cx,50
	cmp cx,151
    je  isredl
	cmp cx,51
    jne lredn 
	cmp dx,201
	jne lredn
	jmp lredr
isredl:
	cmp	dx,51
	je  lredr
	cmp dx,101
	je  lredr
	jmp lredn	
	
lredn:
	sub cx,50
	cmp al,0     ;可行?
	jne lfcon	 ;不黑
	add cx,50
	mov al,0
	call draw
	mov al,9
	sub cx,50
	call draw
	mov [di],cx ;重记worker位置
	jmp near ptr waiting  ;等待
	
lredr:
	sub cx,50
	cmp al,0     ;可行?
	jne lfcon	 ;不黑
	add cx,50
	mov al,5
	call draw
	mov al,9
	sub cx,50
	call draw
	mov [di],cx ;重记worker位置
	jmp near ptr waiting  ;等待	
;--------------------------------------------	
lfcon:	
	cmp al,5;前方是否红
    je  redaheadlf;是红
    cmp al,2;前方是否绿
    je  greenaheadlf;是绿
    cmp al,15;前方是否白         
	je  near ptr waiting     ;撞墙
	cmp al,14;前方是否黄(箱子)              
	je  yellowaheadlf          
	
;--------------------------------------------
redaheadlf:
	add cx,50
	;判断所在是否为红
	cmp cx,151
    je  rlcj
	cmp cx,51
    jne raln 
	cmp dx,201
	jne raln
	jmp ralr
rlcj:
	cmp	dx,51
	je  ralr
	cmp dx,101
	je  ralr
	jmp raln
	
ralr:
	mov al,5   ;自己所在为红
	call draw
	sub cx,50
	mov al,9
	call draw
	mov [di],cx ;重记worker位置
	jmp near ptr waiting
raln:               
	mov al,0   ;自己所在非红
	call draw
	sub cx,50
	mov al,9
	call draw
	mov [di],cx
	jmp near ptr waiting
;--------------------------------------------
greenaheadlf:
	sub cx,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 cx,100
	;判断所在是否为红
	cmp cx,151
    je  glcj
	cmp cx,51
    jne galn 
	cmp dx,201
	jne galn
	jmp galr
glcj:
	cmp	dx,51
	je  galr
	cmp dx,101
	je  galr
	jmp galn
	
galr:	
	sub cx,100	
	int 10h		;读像素
	
	cmp al,5	;更前方是否为红
	je	lgfredr
	
	add cx,100	;更前方为黑
	mov al,5
	call draw
	sub cx,50
	mov al,9
	call draw
	mov [di],cx
	sub cx,50
	mov al,14
	call draw
	
	jmp near ptr waiting
	
lgfredr:
	add cx,100
	mov al,5
	call draw
	sub cx,50
	mov al,9
	call draw
	mov [di],cx
	sub cx,50
	mov al,2
	call draw
	
	jmp near ptr waiting
	     
galn:	
	sub cx,100	
	int 10h		;读像素
	
	cmp al,5	;更前方是否为红
	je	lgfredn
	
	add cx,100	;更前方为黑
	mov al,0
	call draw
	sub cx,50
	mov al,9
	call draw
	mov [di],cx
	sub cx,50
	mov al,14
	call draw
	
	jmp near ptr waiting
	
lgfredn:
	add cx,100
	mov al,0
	call draw
	sub cx,50
	mov al,9
	call draw
	mov [di],cx
	sub cx,50
	mov al,2
	call draw
	
	
	jmp near ptr waiting
	     



;----------------------------------------------------------
yellowaheadlf:
	sub cx,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 cx,100
	
	cmp cx,151
    je  ylcj
	cmp cx,51
    jne yaln 
	cmp dx,201
	jne yaln
	jmp yalr
ylcj:
	cmp	dx,51
	je  yalr
	cmp dx,101
	je  yalr
	jmp yaln
	
	
	
yalr:	
	sub cx,100	
	int 10h		;读像素
	
	cmp al,5	;更前方是否为红
	je	lyfredr
	
	add cx,100	;更前方为黑
	mov al,5
	call draw
	sub cx,50
	mov al,9
	call draw
	mov [di],cx
	sub cx,50
	mov al,14
	call draw

	jmp near ptr waiting
	
lyfredr:
	add cx,100
	mov al,5
	call draw
	sub cx,50
	mov al,9
	call draw
	mov [di],cx
	sub cx,50
	mov al,2
	call draw
	push si
	
	jmp near ptr waiting
	     
yaln:	
	sub cx,100	
	int 10h		;读像素
	
	cmp al,5	;更前方是否为红
	je	lyfredn
	
	add cx,100	;更前方为黑
	mov al,0
	call draw
	sub cx,50
	mov al,9
	call draw
	mov [di],cx
	sub cx,50
	mov al,14
	call draw
	
	jmp near ptr waiting
	
lyfredn:
	add cx,100
	mov al,0
	call draw
	sub cx,50
	mov al,9
	call draw
	mov [di],cx
	sub cx,50
	mov al,2
	call draw
	
	jmp near ptr waiting
;------------------------------------------------------------------------------------------------------------
rtwards:
	mov ah,0dh ;读像素
	mov bh,0
	mov dx,[si]
	mov cx,[di]
	add cx,50
	int 10h
	;判断所在是否为红
	sub cx,50
	cmp cx,151
    je  isredr
	cmp cx,51
    jne rredn 
	cmp dx,201
	jne rredn
	jmp rredr
isredr:
	cmp	dx,51
	je  rredr
	cmp dx,101
	je  rredr
	jmp rredn	

rredn:
	add cx,50	
	cmp al,0     ;可行?
	jne rtcon	 ;不黑
	sub cx,50
	mov al,0
	call draw
	mov al,9
	add cx,50
	call draw
	mov [di],cx ;重记worker位置
	jmp near ptr waiting  ;等待
rredr:
	add cx,50	
	cmp al,0     ;可行?
	jne rtcon	 ;不黑
	sub cx,50
	mov al,5
	call draw
	mov al,9
	add cx,50
	call draw
	mov [di],cx ;重记worker位置
	jmp near ptr waiting  ;等待
;--------------------------------------------	
rtcon:	
	cmp al,5;前方是否红
    je  redaheadrt;是红
    cmp al,2;前方是否绿
    je  greenaheadrt;是绿
    cmp al,15;前方是否白         
	je  near ptr waiting     ;撞墙
	cmp al,14;前方是否黄(箱子)              
	je  yellowaheadrt          
	
;--------------------------------------------
redaheadrt:
	sub cx,50
	;判断所在是否为红
	 
	cmp cx,151
    je  rrcj
	cmp cx,51
    jne rarn 
	cmp dx,201
	jne rarn
	jmp rarr
rrcj:
	cmp	dx,51
	je  rarr
	cmp dx,101
	je  rarr
	jmp rarn
	
rarr:
	mov al,5   ;自己所在为红
	call draw
	add cx,50
	mov al,9
	call draw
	mov [di],cx ;重记worker位置
	jmp near ptr waiting
rarn:               
	mov al,0   ;自己所在非红
	call draw
	add cx,50
	mov al,9
	call draw
	mov [di],cx
	jmp near ptr waiting
;--------------------------------------------
greenaheadrt:
	add cx,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 cx,100
	;判断所在是否为红
	 
	cmp cx,151
    je  grcj
	cmp cx,51
    jne garn 
	cmp dx,201
	jne garn
	jmp garr
grcj:
	cmp	dx,51
	je  garr
	cmp dx,101
	je  garr
	jmp garn
	
garr:	
	add cx,100	
	int 10h		;读像素
	
	cmp al,5	;更前方是否为红
	je	rgfredr
	
	sub cx,100	;更前方为黑
	mov al,5
	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
	
rgfredr:
	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
	     
garn:	
	add cx,100	
	int 10h		;读像素
	
	cmp al,5	;更前方是否为红
	je	rgfredn
	
	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
	
rgfredn:
	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
	     



;----------------------------------------------------------
yellowaheadrt:
	add cx,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 cx,100
	;判断所在是否为红
	 
	cmp cx,151
    je  yrcj
	cmp cx,51
    jne yarn 
	cmp dx,201
	jne yarn
	jmp yarr
yrcj:
	cmp	dx,51
	je  yarr
	cmp dx,101
	je  yarr
	jmp yarn
	
	
yarr:	
	add cx,100	
	int 10h		;读像素
	
	cmp al,5	;更前方是否为红
	je	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,14

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -