欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

汇编实现扫雷程序

程序员文章站 2022-04-12 23:28:13
...

Talking is cheap,show me the code!

;2018/12/18  AUTHOR : SGC

STACK SEGMENT STACK
	DB 10H DUP (0)
STACK ENDS
	
DATA SEGMENT
	MESSAGE1 DB "Blast! ", 0DH, 0AH, '$'
	MESSAGE2 DB "Game over! ", 0DH, 0AH, '$'
	MESSAGE3 DB "The remain bomb is : $" 
	MESSAGE4 DB "Input error,try again : ", 0DH, 0AH, '$' 
	MESSAGE5 DB "Input the number of bombs:(1-9)" , '$' 
	MESSAGE6 DB "Input the rows :(1-9)" , '$' 
	GameWin db "Win the Game! ", 0DH, 0AH, '$'
	KONG DB  0DH, 0AH, '$'
	ROWS DB '  123456789$'
	ROW1 DB '  ---------$' 
	LINE DW '1'
	; 棋盘
	QIPAN DB 81 DUP ('?')
	REALQIPAN DB 81 DUP(0)
	 
	TEMP DB 0
	ACTION DB 0 ;动作
	X db 0  ;行指针
	Y db 0	;列指针
	HANGLIE DB 0
	NUMB DB 0
	GESHU DB 0
DATA ENDS


CODES SEGMENT
    ASSUME CS:CODES,DS:DATA,SS:STACK
STA:
    MOV AX,DATA
    MOV DS,AX
    
    MOV AX, STACK
	MOV SS, AX
    ;此处输入代码段代码
	
SHOW MACRO  
	;PUSH
	
	MOV DX, OFFSET KONG
	MOV AH, 09H
	INT 21H  
	
	MOV DX, OFFSET ROWS	 
	INT 21H       ;输出字符串
	MOV DX, OFFSET KONG
	INT 21H
	
	MOV DX, OFFSET ROW1	 
 	INT 21H       ;输出字符串
	MOV DX, OFFSET KONG
	INT 21H
	
	MOV SI,OFFSET QIPAN
	MOV BL,HANGLIE
	
 	MOV LINE,'1'
 	PUSH LINE
OUTLINES:
	MOV CH,0
	MOV CL,HANGLIE
	POP LINE
	MOV DX,LINE
	MOV AH,2
	INT 21H			;输出行号
	INC LINE
	PUSH LINE
	MOV DX,'|'
	INT 21H
OUTROWS:

	
	LODSB    ;放入al
ABC:
	MOV DL,AL
	MOV AH,2
	INT 21H				;输出棋盘格子
	
	 
	
	LOOP OUTROWS
	
	MOV DX, OFFSET KONG
	MOV AH, 09H
	INT 21H       ;输出字符串
	
	
	MOV CL,BL
	DEC BL	
	LOOP OUTLINES
	
	;POP   
    
    
ENDM  

    
     
START:

	MOV DX, OFFSET MESSAGE6
	MOV AH, 09H
	INT 21H       ;输出字符串
	
    MOV AH,1
    INT 21H      ;输入大小字符
    
    MOV HANGLIE,AL
	SUB HANGLIE,30H  ;棋盘大小
    
    MOV BL,HANGLIE
    MOV BH,0
    ADD BL,2
    MOV ROWS[BX],'$' 
    MOV ROW1[BX],'$'
    
    MOV DX, OFFSET KONG
	MOV AH, 09H
	INT 21H       ;输出字符串
	
    MOV DX, OFFSET MESSAGE5
	MOV AH, 09H
	INT 21H       ;提示输入雷的个数
	
	MOV AH,1
    INT 21H      ;输入大小字符
    
    MOV NUMB,AL
	SUB NUMB,30H  ;雷的个数
	
	;生成雷阵
	
	MOV CH,0    
	MOV CL,NUMB
	MOV AL,HANGLIE
	MUL AL
	MOV GESHU,AL    
	DIV NUMB
	MOV BX,0
	MOV AH,0
PROLEI:
	 
	ADD BX,AX
 	DEC BX
	MOV REALQIPAN[BX],'*'		
	LOOP PROLEI	
	
	;计算雷阵
	MOV CL,GESHU
 
	MOV CH,0
CALC:
	
	MOV TEMP,0
	MOV AX,CX
	MOV BX,AX
	CMP REALQIPAN[BX],'*'
	JNE NN
	LOOP CALC
NN:	
	PUSH AX
	MOV AX,CX
	DIV HANGLIE
	MOV BX,AX
	POP AX
	PUSH BX
	CMP BH,0
	JE NEXT1
	CMP BL,0
	JE NEXT1
	
	MOV AH,AL  ;ZS
	DEC AH
	SUB AH, HANGLIE
	MOV BL,AH
	MOV BH,0
	CMP REALQIPAN[BX],'*'
	JNE NEXT1
	INC TEMP
NEXT1:

	 
	POP BX
	PUSH BX
	CMP BL,0
	JE NEXT2
	
	MOV AH,AL  ;S
	 
	SUB AH, HANGLIE
	MOV BL,AH
	MOV BH,0
	CMP REALQIPAN[BX],'*'
	JNE NEXT2
	INC TEMP
NEXT2:
	POP BX
	PUSH BX
	CMP BL,0
	JE NEXT3
	MOV AH,HANGLIE
	DEC AH
	CMP AH,BH
	JE NEXT3
	
	MOV AH,AL  ;YS
	INC AH
	SUB AH, HANGLIE
	MOV BL,AH
	MOV BH,0
	CMP REALQIPAN[BX],'*'
	JNE NEXT3
	INC TEMP		
NEXT3:
	POP BX
	PUSH BX
	CMP BH,0
	JE NEXT4
	
	MOV AH,AL  ;Z
	DEC AH
	MOV BL,AH
	MOV BH,0
	CMP REALQIPAN[BX],'*'
	JNE NEXT4
	INC TEMP		
NEXT4:
	POP BX
	PUSH BX
	 
	MOV AH,HANGLIE
	DEC AH
	CMP AH,BH
	JE NEXT5
	
	
	MOV AH,AL  ;Y
	INC AH
	MOV BL,AH
	MOV BH,0
	CMP REALQIPAN[BX],'*'
	JNE NEXT5
	INC TEMP		
NEXT5:
	POP BX
	PUSH BX
	CMP BH,0
	JE NEXT6
	MOV AH,HANGLIE
	DEC AH
	CMP AH,BL
	JE NEXT6
	
	MOV AH,AL  ;ZX
	DEC AH
	ADD AH, HANGLIE
	MOV BL,AH
	MOV BH,0
	CMP REALQIPAN[BX],'*'
	JNE NEXT6
	INC TEMP
	JNE NEXT6
C1:
	JMP CALC			
NEXT6:
	POP BX
	PUSH BX
	 
	MOV AH,HANGLIE
	DEC AH
	CMP AH,BL
	JE NEXT7
	
	MOV AH,AL  ;X
	ADD AH, HANGLIE
	MOV BL,AH
	MOV BH,0
	CMP REALQIPAN[BX],'*'
	JNE NEXT7
	INC TEMP		
NEXT7:
	POP BX
	PUSH BX
	
	MOV AH,HANGLIE
	DEC AH
	CMP AH,BH
	JE NEXT8
	CMP AH,BL
	JE NEXT8
	
	MOV AH,AL  ;YX
	INC AH
	ADD AH, HANGLIE
	MOV BL,AH
	MOV BH,0
	CMP REALQIPAN[BX],'*'
	JNE NEXT8
	INC TEMP		
NEXT8:
	MOV BL,AL
	MOV BH,0
	MOV AL,TEMP
	MOV REALQIPAN[BX],AL								
	LOOP C1
	
	MOV TEMP,0
	MOV BX,0
	CMP REALQIPAN[BX+1],'*'
	JNE N1
	INC TEMP
N1:	ADD BL,HANGLIE
	CMP REALQIPAN[BX],'*'
	JNE N2
	INC TEMP
N2:	CMP REALQIPAN[BX+1],'*'
	JNE N3
	INC TEMP
N3: MOV AL,TEMP
	MOV REALQIPAN,AL	

SH:	
	 SHOW  
	 JMP INPUTT
RETRY:
	MOV DX,OFFSET MESSAGE4
	MOV AH,09H
	INT 21H
	
INPUTT:
	 
	MOV AH,1
	INT 21H
	MOV ACTION ,AL
	 
	INT 21H
	MOV X ,AL
	INT 21H
	MOV Y ,AL
	
	MOV DX,OFFSET KONG
	MOV AH,09H
	INT 21H
 
	
	SUB X,30H
	SUB Y,30H
	CMP X,10
	JA RETRY
	CMP Y,10
	JA RETRY
	
	CMP ACTION,'M'
	JNE ACLEI
	
	DEC X
	DEC Y
	MOV AL,HANGLIE
	MUL X 
	ADD AL,Y
	MOV BX,AX
	CMP REALQIPAN[BX],'*'
	JNE NOTEQ
	DEC NUMB
	CMP NUMB,0
	JE WIN
NOTEQ:
	MOV QIPAN[BX] ,'M'

	JMP SH
	
ACLEI:
	CMP ACTION,'A'
	JNE RETRY
		
	DEC X
	DEC Y
	MOV AL,HANGLIE
	MUL X 
	ADD AL,Y
	MOV BX,AX
	CMP REALQIPAN[BX],'*'
	JE BLEAST

	MOV AL,REALQIPAN[BX]
	ADD AL,30H
	MOV QIPAN[BX],AL
	JMP SH


WIN:
	MOV DX,OFFSET GameWin
	MOV AH,09H
	INT 21H
	JMP EN

BLEAST:
	MOV DX,OFFSET MESSAGE1
	MOV AH,09H
	INT 21H
	MOV DX,OFFSET MESSAGE2
	INT 21H
 
	
	JMP EN
     
EN:   
    
    MOV AH,4CH
    INT 21H
CODES ENDS
    END STA 

使用说明

首先输入棋盘行数和地雷个数。
输入完成后,会生成棋盘。
汇编实现扫雷程序

’A’代表挖雷操作(可能会被雷炸死),'M’代表标记雷操作。然后输入行数和列数。这三个数构成一组输入。
汇编实现扫雷程序
微机课设小心查重吆 *O_O*

相关标签: 汇编