汇编语言写的贪吃蛇小游戏源代码

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

DATA SEGMENT

dw 0,0

snk db 1

blk db 32

food db 3

tal1 db 4

tal2 db 2

adrs db 5

len db ?

pst db ?

addrs dw ?

frow db ?

fcol db ?

hwrt db ?

gmov db 'game over press r to restart press q to quit $'

score1 db 'score :$'

score2 db ?

score0 db 1

zero db 48

writer db 'Developer: Geniusdot $'

email db ': geniusdotgmail.$'

msg1 db 'The way to play the game:$'

way db ' press w to up ,press s to down,press a to left,press d to right$' msg db 'Press any key(except a,s,d,w) to start$'

DATA ENDS

STACK SEGMENT stack

db 200 dup(0)

STACK ENDS

CODE SEGMENT

ASSUME CS:CODE,DS:DATA,SS:STACK

start:

mov ax,data

mov ds,ax

mov ax,0

mov es,ax

mov frow,10

mov fcol,6

mov dh,10

mov dl,26

mov ah,2

int 10h

mov ah,9

lea dx,msg1 int 21h

mov dh,11 mov dl,7

mov ah,2

mov bh,0

int 10h

mov ah,9

lea dx,way

int 21h

mov dh,12 mov dl,20 mov ah,2

mov bh,0

int 10h

mov ah,9

lea dx,msg

int 21h

mov ah,0

int 16h

mov ah,6

mov al,0

mov ch,0

mov cl,0

mov dh,24 mov dl,79 mov bh,10

int 10h

mov dh,0

mov dl,0

mov ah,2

mov bh,0

int 10h

mov ah,9

lea dx,score1 int 21h

mov dl,15 mov ah,2

mov bh,0

int 10h

lea dx,writer

int 21h

mov ah,9

lea dx,email

int 21h

mov score2,48

push es:[9*4] ;将原int9入口地址保存

pop ds:[0]

push es:[9*4+2]

pop ds:[2]

mov word ptr es:[9*4],offset int9 ;更改中断向量表

mov es:[9*4+2],cs

jmp aa

write macro row,col,cnt ;宏定义用于向当前光标处输出字符

push bx

push cx

push dx

mov dh,row

mov dl,col

mov ah,2

mov bh,0

int 10h

mov ah,9

mov bl,11

mov cx,1

lea di,cnt ;50

mov al,[di]

int 10h

pop dx

pop cx

pop bx

endm

readh macro row,col ;宏定义用于读出当前光标处字符

push dx

push bx

mov dh,row

mov dl,col

mov ah,2

mov bh,0

int 10h

mov ah,08h

int 10h

mov pst,al

pop bx

pop ax

pop dx

endm

wnear macro ;宏定义只用在readcg宏中当readcg的所有判断都不成立调用此宏

local wnext1

local wnext2

local wnext3

local wnext4

push dx

dec dh

readh dh,dl

cmp pst,1

jne wnext1

write dh,dl,tal2

jmp wnext4

wnext1:

inc dh

dec dl

readh dh,dl

cmp pst,1

jne wnext2

write dh,dl,tal2

jmp wnext4

wnext2:

inc dh

inc dl

readh dh,dl

cmp pst,1

jne wnext3

write dh,dl,tal2

jmp wnext4

相关文档
最新文档