求用汇编语言编写的小游戏代码
发布网友
发布时间:2022-05-14 17:36
我来回答
共4个回答
热心网友
时间:2023-10-17 05:07
code
segment
assume
cs:code,
ds:code
org
100h
start:
push
0b800h
pop
es
push
cs
pop
ds
mov
cx,
0fffh
;========清屏
rep
stosw
drawfen:
;========分数标签
lea
si,
fen
mov
di,
160+10
call
print
sub
di,
4
mov
[fi],
di
;label
cursor
drawfoot:
;========摆放食物
mov
di,
160+40
mov
ax,
0a05h
mov
cl,
8
drf:
add
di,
160*2+90
stosw
loop
drf
drawqian:
;========绘制墙壁
xor
di,
di
mov
cl,
80
mov
ax,
0c1fh
repnz
stosw
mov
di,
160*24
mov
cl,
80
mov
ax,
0c1eh
repnz
stosw
xor
di,
di
mov
cl,
24
mov
ax,
0c10h
q1:
mov
es:[di],
ax
add
di,
160
loop
q1
mov
di,
158
mov
cl,
24
mov
ax,
0c11h
q2:
mov
es:[di],
ax
add
di,
160
loop
q2
;============================初始化蛇的数据
inits:
mov
bp,
0
;bp=方向,
ch=节数,
[snake+_newxy]=xy坐标
mov
ch,
3
mov
word
ptr[snake+_newxy],
_center
mainl:
;游戏开始
call
movsnake
call
operkey
jmp
short
mainl
exit:
lea
si,
over
mov
di,
_center
call
print
int
20h
;结束
;===========================移动头
movsnake:
lea
si,
snake
mov
bx,
word
ptr[si+_newxy]
;get
currentxy
push
bx
add
bx,
word
ptr[dir+bp]
;add
offsetxy
mov
ax,
es:[bx]
cmp
al,
01h
;撞到自己的身体
je
exit
cmp
al,
10h
;撞到墙
je
exit
cmp
al,
11h
;撞到墙
je
exit
cmp
al,
1eh
;撞到墙
je
exit
cmp
al,
1fh
;撞到墙
je
exit
cmp
al,
05h
;吃食物
jne
mgo
call
eat
mgo:
mov
word
ptr[si+_newxy],bx
;update
mov
word
ptr
es:[bx],
0e02h
;drawhead
('_')
pop
bx
mov
word
ptr[si+_oldxy],
bx
;save
oldxy
add
si,
_len
;==============移动并绘制身体
mov
cl,
ch
dec
cl
jz
mb
mlin:
push
word
ptr[si+_newxy]
;save
currentxy
mov
di,
word
ptr[si-_len+_oldxy]
;get
prev.oldxy
mov
word
ptr[si+_newxy],
di
;update
currentxy
mov
ax,
1e01h
;draw
body
stosw
pop
word
ptr[si+_oldxy]
;save
oldxy
add
si,
_len
;get
next
dec
cl
jnz
mlin
mov
di,
word
ptr[si-_len+_oldxy]
;erase
the
last!
xor
ax,
ax
stosw
mb:
ret
;=======================吃食物
eat:
inc
ch
;
jns
v0
jmp
exit
v0:
mov
word
ptr
es:[bx],
0
;erase
it
mov
di,
bx
add
di,
90
cmp
di,
0f00h
jb
v2
mov
di,
dx
and
di,
0f00h
v2:mov
word
ptr
es:[di],
0a05h
mov
di,
word
ptr
[fi]
;只能显示到99
cmp
byte
ptr
es:[di],'9'
jb
v1
mov
byte
ptr
es:[di],
'0'
sub
di,
2
v1:
inc
byte
ptr
es:[di]
ret
;=====================显示字符串
print:
mov
ah,
0dh
sa:
lodsb
stosw
cmp
al,
0
jnz
sa
ret
;=====================键盘操纵区
operkey:
;the
operator
key
for
game
push
bx
cx
mov
ah,
0
int
1ah
add
dx,
4
mov
bx,
dx
wt:
int
1ah
cmp
dx,
bx
jb
wt
pop
cx
bx
in
al,
60h
k0:
cmp
al,
left
jne
k1
mov
bp,
0
k1:
cmp
al,
right
jne
k2
mov
bp,
2
k2:
cmp
al,
up
jne
k3
mov
bp,
4
k3:
cmp
al,
down
jne
k4
mov
bp,
6
k4:
cmp
al,
escape
jne
retk
jmp
exit
retk:
ret
;========================数据区
over
db
'game
over',
0
fen
db
'score=000',
0
fi
dw
?
dir
dw
-2,
+2,
-160,
+160
_center
equ
160*12+60
_newxy
equ
0
_oldxy
equ
2
_len
equ
4
left
equ
75
right
equ
77
up
equ
72
down
equ
80
escape
equ
1
snake:
code
ends
end
start
热心网友
时间:2023-10-17 05:07
前两天刚编了一个“贪吃蛇”的游戏。虽然是小游戏,功能非常简单,整整做了两天才出来,但代码300多行。
热心网友
时间:2023-10-17 05:08
让楼主满意:小游戏代码
http://tieba.baidu.com/f?kz=596559580
热心网友
时间:2023-10-17 05:08
在百度debug吧里有个贪吃蛇的游戏,只不过是机器码的,需要先翻成汇编语言。