data segment
hang	dw  50 dup (0043h,0042h,0041h,0040h)
ram	dw  50 dup (000fh,000fh,000fh,000fh)
flag	db	0
mid	dw	0001h
beanX	dw	?
beanY	dw	?
Len	dw	4
data ends
code segment
	assume cs:code,ds:data
main proc far
start:	mov ax,data
	mov ds,ax
	;mov ah,0fh
	;mov bh,0
	;int 10h
	;push ax	;保存原来显示模式
	mov ah,00	;图形模式
	mov al,4h
	int 10h
	mov ah,0bh	;设背景色
	mov bh,00
	mov bl,00
	int 10h
	mov ah,0bh	;设调色板0
	mov bh,01h
	mov bl,1
	int 10h
	mov cx,Len
xxx:	cmp flag,0
	jnz zou
	call GetRam
	inc flag
zou:	mov cx,Len	;恢复蛇身长度
	mov si,0
xx:	push cx		;begin打印蛇身
	mov ah,0ch
	mov al,02
	mov dx,hang[si]
	mov cx,ram[si]
	add si,2
	inc di
	int 10h
	pop cx
	loop xx		;/begin打印蛇身
	call delay
	mov ax,hang[0]	;判断是否吃掉
	cmp ax,beanY
	jnz nequ
	mov ax,ram[0]
	cmp ax,beanX
	jnz nequ	
	call GetRam	;如果吃掉粒子就再次产生
	inc Len
nequ:	mov cx,Len
	push cx
	call x2
	mov ah,0ch
	mov al,00
	mov dx,hang[si-2]	
	mov cx,ram[si-2]
	int 10h
	pop cx
	dec cx
cir:	call x2	;begin除蛇头外更新堆栈	
	mov dx,hang[si-2]
	mov hang[si],dx
	mov dx,ram[si-2]
	mov ram[si],dx
	loop cir	;/begin
	call vary	;更新蛇头
	call IsOut?
	mov ah,0ch	;清空键盘缓冲区	
	mov al,02h
	int 21h
	jmp xxx		
 	;pop ax		;恢复显示器模式
	;mov ah,00
	;int 10h
	;mov ah,4ch	;返回DOS
	;int 21h
main endp
LenEn	proc near
	ret
LenEn	endp
x2 proc near
	;push bx
	;push ax
	;push cx
	mov ax,cx
	mov bl,2
	mul bl
	mov si,ax
	;pop cx
	;pop ax
	;pop bx
	ret

x2 endp
GetRam proc near
	;push ax
	;push bx
	;push cx
	;push dx
	mov ah,0
	int 1ah
	mov ax,dx
	and ah,0
	mov dl,199
	div dl
	mov al,ah
	mov ah,00h
	mov beanY,ax
	mov ah,0
	int 1ah
	mov ax,dx
	mov dl,255
	div dl
	mov al,ah
	mov ah,00h
	mov beanX,ax
	mov ah,0ch
	mov al,1
	mov dx,beanY
	mov cx,beanX
	int 10h
	;pop dx
	;pop cx
	;pop bx
	;pop ax
	ret
GetRam endp
vary proc near
	;push ax
	;push si
	;push bx
	mov si,0h
	mov ah,01h
	int 16h
	jz judge
	cmp ah,4dh	;right->
	jnz one
	cmp flag,4	;目的是检测按键是否与运行方向相反
	jz one		;禁止方向移动
	jmp la	
one:	cmp ah,4bh 	;left<-
	jnz two
	cmp flag,3	;目的是检测按键是否与运行方向相反
	jz two 		;禁止方向移动
	jmp ls
two:	cmp ah,48h	;up ^
	jnz three
	cmp flag,1	;目的是检测按键是否与运行方向相反
	jz three	;禁止方向移动
	jmp hs
three:	cmp ah,50h	;down
	jnz judge
	cmp flag,2	;目的是检测按键是否与运行方向相反
	jz f1 		;禁止方向移动
	jmp ha
judge:	cmp flag,1
	jnz f1
	jmp ha
f1:	cmp flag,2
	jnz f2
	jmp hs
f2:	cmp flag,3
	jnz ls
	jmp la
ha:	mov bx,mid
	add hang[si],bx
	mov flag,1
	jmp over
hs:	mov bx,mid
	sub hang[si],bx
	mov flag,2
	jmp over
la:	mov bx,mid
	add ram[si],bx
	mov flag,3
	jmp over
ls:	mov bx,mid
	sub ram[si],bx
	mov flag,4
over:	;pop bx
	;pop si
	;pop ax
	ret
vary endp
delay	proc near
	;push si
	;push cx
	mov si,100h
	mov cx,0
circ:	loop $
	dec si
	jnz circ
	;pop cx
	;pop si
	ret
delay endp
IsOut?	proc near
	cmp ram[0],320
	jnz notRO
	mov ram[0],0000h
notRO:	cmp ram[0],0ffffh
	jnz notLO
	mov ram[0],319
notLO: 	cmp hang[0],0ffffh
	jnz notUO
	mov hang[0],199
notUO:	cmp hang[0],200
	jnz exo
	mov hang[0],0000h
exo:	ret
IsOut?  endp
code ends
	end  start;sum of 252row
 	;1.随即产生粒子:取时间秒,个位与十位相乘结果乘5除200取余数为行,成绩再乘8结果除300取余得列
	;2边界
	;3判断头坐标,头坐标是否与达堆栈相同,则结束游戏
	;4禁止向相反方向移动,在按键后判断flag内容如果与反方向相同则跳到原方向,不同则不变flag0,falg1,flag2,flag3  
	;俄罗斯方块,建立与窗体相对应得二维数组,当方块触底后,数组置1,   时刻检测数组中同行是否为全一,则该行清零且以上为一得位置均下移相应行数
打赏