收藏 分享(赏)

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

上传人:HR专家 文档编号:6513280 上传时间:2019-04-14 格式:DOC 页数:20 大小:78KB
下载 相关 举报
汇编语言写的贪吃蛇小游戏源代码.doc_第1页
第1页 / 共20页
汇编语言写的贪吃蛇小游戏源代码.doc_第2页
第2页 / 共20页
汇编语言写的贪吃蛇小游戏源代码.doc_第3页
第3页 / 共20页
汇编语言写的贪吃蛇小游戏源代码.doc_第4页
第4页 / 共20页
汇编语言写的贪吃蛇小游戏源代码.doc_第5页
第5页 / 共20页
点击查看更多>>
资源描述

1、DATA SEGMENTdw 0,0snk db 1blk db 32food db 3tal1 db 4tal2 db 2adrs db 5len 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 1zero db 48writer db Developer: Geniusdot $email db e-mail: $msg1 db The way to pla

2、y 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 ENDSSTACK SEGMENT stackdb 200 dup(0)STACK ENDSCODE SEGMENTASSUME CS:CODE,DS:DATA,SS:STACKstart:mov ax,datamov ds,axmov ax,0mov es,axmov frow,10mov fcol,6mov dh,10 mov

3、 dl,26mov ah,2mov bh,0int 10hmov ah,9lea dx,msg1int 21hmov dh,11mov dl,7mov ah,2mov bh,0int 10hmov ah,9lea dx,wayint 21hmov dh,12mov dl,20mov ah,2mov bh,0int 10hmov ah,9lea dx,msgint 21hmov ah,0int 16hmov ah,6mov al,0mov ch,0mov cl,0mov dh,24mov dl,79mov bh,10int 10hmov dh,0mov dl,0mov ah,2mov bh,0i

4、nt 10hmov ah,9lea dx,score1int 21hmov dl,15mov ah,2mov bh,0int 10hmov ah,9lea dx,writerint 21hmov ah,9lea dx,emailint 21hmov score2,48push es:9*4 ;将原 int9 入口地址保存pop ds:0push es:9*4+2pop ds:2mov word ptr es:9*4,offset int9 ;更改中断向量表mov es:9*4+2,csjmp aawrite macro row,col,cnt ;宏定义用于向当前光标处输出字符push bxpu

5、sh cxpush dxmov dh,rowmov dl,colmov ah,2mov bh,0int 10hmov ah,9mov bl,11mov cx,1lea di,cnt ;50mov al,diint 10hpop dxpop cxpop bxendmreadh macro row,col ;宏定义用于读出当前光标处字符 push dxpush axpush bxmov dh,rowmov dl,colmov ah,2mov bh,0int 10hmov ah,08hint 10hmov pst,alpop bxpop axpop dxendmwnear macro ;宏定义只用在

6、readcg 宏中当 readcg 的所有判断都不成立调用此宏local wnext1local wnext2local wnext3local wnext4push dxdec dhreadh dh,dlcmp pst,1jne wnext1write dh,dl,tal2jmp wnext4wnext1:inc dhdec dlreadh dh,dlcmp pst,1jne wnext2write dh,dl,tal2jmp wnext4wnext2:inc dhinc dlreadh dh,dlcmp pst,1jne wnext3write dh,dl,tal2jmp wnext4wn

7、ext3:dec dhinc dlreadh dh,dlcmp pst,1jne wnext4write dh,dl,tal2wnext4:pop dxendmreadcg macro row,col ;宏定义用于改变判断出来的字符local tnup,tnup1,tnup2,tnlf,tnlf1,tnlf2,tndn,tndn1,tndn2,tnrt,tnrt1,tnrt2,gooutpush bxpush axpush dxwrite dh,dl,tal1dec rowreadh dh,dlcmp pst,4jne tnup1jmp tnup2tnup1:jmp near ptr tnup

8、tnup2:write dh,dl,blkinc dhinc dhreadh dh,dlcmp pst,1jne tnupwrite dh,dl,tal2jmp near ptr goouttnup:pop dxpush dxdec colreadh dh,dlcmp pst,4jne tnlf1jmp tnlf2tnlf1:jmp near ptr tnlftnlf2:write dh,dl,blkinc dlinc dlreadh dh,dlcmp pst,1jne tnlfwrite dh,dl,tal2jmp near ptr goouttnlf:pop dxpush dxinc ro

9、wreadh dh,dlcmp pst,4jne tndn1jmp tndn2tndn1:jmp near ptr tndntndn2:write dh,dl,blkdec dhdec dhreadh dh,dlcmp pst,1jne tndnwrite dh,dl,tal2jmp near ptr goouttndn:pop dxpush dxinc colreadh dh,dlcmp pst,4jne tnrt1jmp tnrt2tnrt1:jmp near ptr tnrttnrt2:write dh,dl,blkdec dldec dlreadh dh,dlcmp pst,1jne

10、tnrtwrite dh,dl,tal2jmp near ptr goouttnrt:pop dxpush dxwneargoout:pop dxpop axpop bxendmaddone: ;此标号功能是将蛇身增加一push dxinc score2mov dh,1mov dl,0mov cx,23cmpad1:push cxmov cx,79cmpad2:readh dh,dlcmp pst,2jne nextad3jmp nextad4nextad3:jmp near ptr nextadnextad4:write dh,dl,snkdec dhreadh dh,dlcmp pst,4

11、jne natupwrite dh,dl,tal2dec dhwrite dh,dl,tal1jmp outonatup:inc dhdec dlreadh dh,dlcmp pst,4jne natlfwrite dh,dl,tal2dec dlwrite dh,dl,tal1jmp outonatlf:inc dhinc dlreadh dh,dlcmp pst,4jne natdnwrite dh,dl,tal2inc dhwrite dh,dl,tal1jmp outonatdn:dec dhinc dlreadh dh,dlcmp pst,4jne natrtwrite dh,dl,

12、tal2inc dlwrite dh,dl,tal1natrt:outo:pop cxjmp near ptr endadnextad:inc dljmp nextad2chgad2:jmp near ptr cmpad2nextad2:loop chgad2sub dl,79inc dhpop cxjmp nextad1chgad1:jmp near ptr cmpad1nextad1:loop chgad1endad:pop dxjmp near ptr crtfaa: ;从这开始产生最原始的蛇mov addrs,offset turnrightmov dh,10mov dl,1mov c

13、x,3write dh,dl,tal1inc dlwrite dh,dl,tal2wrt: inc dlwrite dh,dl,snkloop wrtmov len,6mov ax,0jmp wrt1ovflw: ;当蛇碰壁或自身转到此游戏结束mov ah,6mov al,0mov ch,0mov cl,0mov dh,24mov dl,79mov bh,7int 10hmov dh,17mov dl,17mov ah,2mov bh,0int 10hmov ah,9lea dx,gmovint 21hmov ax,0 ;恢复 int9 中断mov es,axpush ds:0pop es:9

14、*4push ds:2pop es:9*4+2stop:mov ah,0int 16hcmp al,rje aa1jmp aa2aa1:jmp near ptr startaa2:cmp al,qjne stopjmp near ptr exitwrt1: ;此处蛇行走过程的无限循环call dlypush dxinc dhcmp dh,25je ovflwinc dlcmp dl,80je ovflwpop dxpush dxdec dhcmp dh,0je ovflwdec dlcmp dl,-1je ovflwpop dxpush dxlea ax,turnrightcmp addrs,

15、axjne tonxt2inc dlreadh dh,dlcmp pst,1je tonxt1cmp pst,2je tonxt1cmp pst,4je tonxt1jmp tonxt2tonxt1:jmp ovflwtonxt2:pop dxpush dxlea ax,turnupcmp addrs,axjne tonxt4dec dhreadh dh,dlcmp pst,1je tonxt3cmp pst,2je tonxt3cmp pst,4je tonxt3jmp tonxt4tonxt3:jmp ovflwtonxt4:pop dxpush dxlea ax,turndowncmp

16、addrs,axjne tonxt6inc dhreadh dh,dlcmp pst,1je tonxt5cmp pst,2je tonxt5cmp pst,4je tonxt5jmp tonxt6tonxt5:jmp ovflwtonxt6:pop dxpush dxlea ax,turnbackcmp addrs,axjne tonxt8dec dlreadh dh,dlcmp pst,1je tonxt7cmp pst,2je tonxt7cmp pst,4je tonxt7jmp tonxt8tonxt7:jmp ovflwtonxt8:pop dxjmp nextacrtf1:jmp

17、 near ptr addonecrtf:call rand1call rand2inc frowmov ah,frowmov al,fcolpush dxmov dh,1mov dl,0push cxmov cx,23check1:push cxmov cx,79check2:readh dh,dlcmp pst,1je nextncmp pst,2je nextncmp pst,4je nextnjmp nextnnnextn:cmp ax,dxje crtfnextnn:inc dlloop check2inc dhsub dl,79pop cxloop check1pop cxpop

18、dxwrite frow,fcol,foodnexta:mov ah,frowmov al,fcolcmp ax,dxje crtf12jmp crtf13crtf12:jmp near ptr crtf1crtf13:push dxcmp score2,58jl normalmov score2,49inc score0normal:mov dh,0mov dl,8write dh,dl,score2add dl,score0write dh,dl,zeropop dxcmp adrs,17je jmp1cmp adrs,145je jmp1cmp adrs,31je jmp2cmp adr

19、s,159je jmp2cmp adrs,32je jmp3cmp adrs,160je jmp3cmp adrs,30je jmp4cmp adrs,158je jmp4jmp addrsjmp1:lea ax, turndowncmp ax,addrsje jmp2mov addrs,offset turnupjmp near ptr turnupjmp2:lea ax,turnupcmp ax,addrsje jmp1mov addrs,offset turndownjmp near ptr turndownjmp3:lea ax,turnbackcmp ax,addrsje jmp4m

20、ov addrs,offset turnrightjmp near ptr turnrightjmp4:lea ax,turnrightcmp ax,addrsje jmp3mov addrs,offset turnbackjmp near ptr turnbackturnright: ;此处实现蛇向左走push dxmov dh,1mov dl,0mov cx,23cmpr1:push cxmov cx,79cmpr2:readh dh,dlcmp pst,2je nextr4jmp near ptr nextrnextr4:readcg dh,dlpop cxjmp near ptr en

21、drnextr:inc dljmp nextr2chgr2:jmp near ptr cmpr2nextr2:loop chgr2sub dl,79inc dhpop cxjmp nextr1chgr1:jmp near ptr cmpr1nextr1:loop chgr1endr:pop dxinc dlwrite dh,dl,snkjmp near ptr wrt1turnup: ;此处实现蛇向上走push dxmov dh,1mov dl,0mov cx,23cmpu1:push cxmov cx,79cmpu2:readh dh,dlcmp pst,2jne nextu3jmp nex

22、tu4nextu3:jmp near ptr nextunextu4:readcg dh,dlpop cxjmp near ptr endunextu:inc dljmp nextu2chgu2:jmp near ptr cmpu2nextu2:loop chgu2sub dl,79inc dhpop cxjmp nextu1chgu1:jmp near ptr cmpu1nextu1:loop chgu1endu:pop dxdec dhwrite dh,dl,snkjmp near ptr wrt1turndown: ;此处实现蛇向下走push dxmov dh,1mov dl,0mov

23、cx,23cmpd1:push cxmov cx,79cmpd2:readh dh,dlcmp pst,2jne nextd3jmp nextd4nextd3:jmp near ptr nextdnextd4:readcg dh,dlpop cxjmp near ptr enddnextd:inc dljmp nextd2chgd2:jmp near ptr cmpd2nextd2:loop chgd2sub dl,79inc dhpop cxjmp nextd1chgd1:jmp near ptr cmpd1nextd1:loop chgd1endd:pop dxinc dhwrite dh

24、,dl,snkjmp near ptr wrt1turnback: ;此处实现蛇向右走push dxmov dh,1mov dl,0mov cx,23cmpb1:push cxmov cx,79cmpb2:readh dh,dlcmp pst,2jne nextb3jmp nextb4nextb3:jmp near ptr nextbnextb4:readcg dh,dlpop cxjmp near ptr endbnextb:inc dljmp nextb2chgb2:jmp near ptr cmpb2nextb2:loop chgb2sub dl,79inc dhpop cxjmp ne

25、xtb1chgb1:jmp near ptr cmpb1nextb1:loop chgb1endb:pop dxdec dlwrite dh,dl,snkjmp near ptr wrt1exit:mov ax,0 ;恢复 int9 中断mov es,axpush ds:0pop es:9*4push ds:2pop es:9*4+2mov ah,4chint 21hint9: ;更改后的中断服务程序push axin al,60hmov adrs,almov al,20hout 20h,alpop axiretDLY PROC near ;延时子程序PUSH CXPUSH DXMOV DX,

26、10000DL1: MOV CX,9801DL2: LOOP DL2DEC DXJNZ DL1POP DXPOP CXRETDLY ENDPRAND1 PROCPUSH CXPUSH DXPUSH AXSTIMOV AH,0 ;读时钟计数器值INT 1AHMOV AX,DX ;清高 6 位AND AH,3MOV DL,23 ;除 23,产生 023 余数DIV DLMOV frow,AH ;余数存 frow,作随机行数POP AXPOP DXPOP CXRETRAND1 ENDPRAND2 PROCPUSH CXPUSH DXPUSH AXSTIMOV AH,0 ;读时钟计数器值INT 1AHMOV AX,DX ;清高 6 位AND AH,3MOV DL,79 ;除 79,产生 079 余数DIV DLMOV fcol,AH ;余数存 fcol,作随机列数POP AXPOP DXPOP CXRETRAND2 ENDPCODE ENDSEND start

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 企业管理 > 经营企划

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报