-
Notifications
You must be signed in to change notification settings - Fork 1
/
game.inc
124 lines (116 loc) · 2.94 KB
/
game.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
.data
CMD_CLEAN byte "cls",0
MY_BLANKS byte " ",0
MY_BLANKS_ byte " ",0
.code
DrawGame proc
call Clrscr ; 清空屏幕
; 绘制地图
invoke SetFontColor,3
invoke InitMap
invoke SetCursorPosition,0,31
; 绘制侧边栏
invoke DrawMainMenu
invoke SetCursorPosition,0,31
ret
DrawGame endp
UpdateScore proc bonus:word
mov ax,bonus
imul ax,MY_DIFFICULTY
add ax,MY_SCORE
mov MY_SCORE,ax
invoke SetFontColor,MY_MENU_COL
invoke _SetCursorPosition,9,8
movzx eax,MY_SCORE
call WriteDec
ret
UpdateScore endp
Playing proc
local tmpscore:word
invoke InitSnake ; 初始化蛇
invoke DrawSnake
invoke InitFood ; 初始化食物属性
invoke Drawfood
myGaming: ; 游戏二级循环
invoke OverEdge
cmp eax,0
jne deathSnake
invoke HitItself
cmp eax,0
jne deathSnake
invoke SetCursorPosition,0,31
invoke RefreshDirection
.if eax==0 ; 按下ESC
invoke DrawESCMenu
.if eax==1 ; 继续游戏
invoke SetCursorPosition,1,26
invoke crt_printf,addr MY_BLANKS
invoke SetCursorPosition,1,28
invoke crt_printf,addr MY_BLANKS
invoke SetCursorPosition,1,30
invoke crt_printf,addr MY_BLANKS
invoke SetCursorPosition,0,31
.elseif eax==2 ; 重新开始
invoke PlaySound, offset MY_SOUND_BACKGROUND,NULL,131081
invoke SetFontColor,0
invoke crt_system,addr CMD_CLEAN
invoke ShowWelcome
invoke ShowSelection
invoke PlaySound, offset NULL,NULL,NULL
invoke PlaySound, offset MY_SOUND_BEGIN,NULL,131073
invoke DrawGame
invoke InitSnake
invoke DrawSnake
invoke InitFood
invoke Drawfood
jmp myGaming
.elseif eax==3 ; 退出游戏
mov eax,0
ret
.endif
.endif
invoke isGetFood
.if eax==1 ; 吃到食物
invoke PlaySound, offset MY_SOUND_GROWTH,NULL,131073
invoke Growing ; 蛇身增长
invoke SetCursorPosition,0,31
invoke UpdateScore,1
invoke SetCursorPosition,0,31
invoke Drawfood
invoke SetCursorPosition,0,31
.else ; 正常移动
invoke Moving
invoke SetCursorPosition,0,31
.endif
.if MY_FOOD_SP_BAR>0 ; 存在奖励食物
invoke BonusTwinkling
invoke SetCursorPosition,0,31
invoke isGetBonus ; 吃到奖励食物
.if eax==1
invoke PlaySound, offset MY_SOUND_GROWTH,NULL,131073
invoke Growing
invoke SetCursorPosition,0,31
mov ax,MY_FOOD_SP_BAR
shr ax,2
or ax,1
mov tmpscore,ax
invoke UpdateScore,tmpscore
mov MY_FOOD_SP_BAR,0
invoke _SetCursorPosition,29,0
invoke crt_printf,addr MY_BLANKS_
invoke SetCursorPosition,0,31
.endif
.endif
movzx eax,MY_SPEED
.if MY_SNAKE_ACC ; 如果方向键相同,则加速蛇的移动
shr eax,1
mov MY_SNAKE_ACC,0
.endif
call Delay
jmp myGaming
deathSnake: ; 蛇死亡,游戏结束
invoke PlaySound, offset NULL,NULL,NULL
invoke PlaySound, offset MY_SOUND_DEATH,NULL,131073
invoke ShowDeathMenu
ret
Playing endp