📄 game.asm
字号:
jmp test2_loop
test2_y_no_equal:
add di, 2
test2_loop:
inc loop_data
mov al , loop_data
cmp num, al
jnz test2_cmp
; ********** test whether head coordinate overflow or not
test3:
cmp head_x, 0
jnb test3_x_2
jmp game_end
test3_x_2:
cmp head_x, 15
jb test3_y_1
jmp game_end
test3_y_1:
cmp head_y, 0
jnb test3_y_2
jmp game_end
test3_y_2:
cmp head_y, 8
jb test_end
jmp game_end
test_end:
call move_one
call check_input
ret
game_end:
call dispose_game_end
ret
dispose_new_coordinate endp
; ************************************************************************************************************************
; ************************************************************************************************************************
; ********** dispose snake body + 1
add_one proc near
call set_new_fruit_coordinates
; ********** achievement add grade and show it
mov ax, 0
mov al, grade
add achievement, ax
mov ax, max_achievement
cmp achievement, ax
jnbe set_new_max_achievement
jmp change_snake1_coordinates
; ********** acquire new max achievement
set_new_max_achievement:
mov ax, achievement
mov max_achievement, ax
call show_max_achievement
; ********** change_snake1_coordinates
change_snake1_coordinates:
call set_new_neck_coordinates
lea di, snake1
mov al, 3
mul num
add di, ax
mov al, neck_x
mov [ di ], al
inc di
mov al, neck_y
mov [ di ], al
inc di
mov al, neck_z
mov [ di ], al
inc num
; ********** sound
call sound
mov al,num
mov x, 20
div x
cmp ah, 0
jnz show_the_achievement
; ********** sound
call sound
inc grade
call show_grade
cmp grade, 6
jz game_complete
; ********** show the achievement
show_the_achievement:
call show_achievement
ret
game_complete:
call game_successful
ret
add_one endp
; ************************************************************************************************************************
; ************************************************************************************************************************
; ********** set new fruit coordinates and show its picture
set_new_fruit_coordinates proc near
lea di, snake1
mov al, [ di ]
mov fruit_new_x, al
mov test_x, al
inc di
mov al, [ di ]
mov fruit_new_y, al
mov test_y, al
inc di
mov al, [ di ]
mov test_z, al
test_tail00:
cmp test_z, 30h
jnz test_tail01
dec test_x
cmp test_x, 0
js test_tail00_set_x_axis
mov al, fruit_new_x
cmp test_x, al
jz test_tail00_set_y_axis
call test_fruit_new_coordinates
cmp al, 0
jz test_tail00
jmp set_fruit_coordinates
test_tail00_set_x_axis:
mov test_x, 15
jmp test_tail00
test_tail00_set_y_axis:
cmp test_y,0
js test_tail00_set_y_new_axis
dec test_y
mov al, fruit_new_y
cmp test_y, al
jz game_success
jmp test_tail00
test_tail00_set_y_new_axis:
mov test_y, 7
jmp test_tail00
test_tail01:
cmp test_z, 31h
jnz test_tail02
dec test_y
cmp test_y, 0
js test_tail01_set_y_axis
mov al, fruit_new_y
cmp test_y, al
jz test_tail01_set_x_axis
call test_fruit_new_coordinates
cmp al, 0
jz test_tail01_set_y_axis
jmp set_fruit_coordinates
test_tail01_set_y_axis:
mov test_y, 8
jmp test_tail01
test_tail01_set_x_axis:
dec test_x
cmp test_x,0
js test_tail01_set_x_new_axis
mov al, fruit_new_x
cmp test_x, al
jz game_success
jmp test_tail01
test_tail01_set_x_new_axis:
mov test_x, 15
jmp test_tail01
test_tail02:
cmp test_z, 32h
jnz test_tail03
inc test_x
cmp test_x, 15
jnb test_tail02_set_x_axis
mov al, fruit_new_x
cmp test_x, al
jz test_tail02_set_y_axis
call test_fruit_new_coordinates
cmp al, 0
jz test_tail02
jmp set_fruit_coordinates
test_tail02_set_x_axis:
mov test_x, -1
jmp test_tail02
test_tail02_set_y_axis:
dec test_y
cmp test_y, 0
jz test_tail02_set_y_new_axis
mov al, fruit_new_y
cmp test_y, al
jz game_success
jmp test_tail02
test_tail02_set_y_new_axis:
mov test_y, 8
jmp test_tail02
test_tail03:
cmp test_z, 33h
jnz wrong_tail_symbol
inc test_y
cmp test_y, 8
jnb test_tail03_set_y_axis
mov al, fruit_new_y
cmp test_y, al
jz test_tail03_set_x_axis
call test_fruit_new_coordinates
cmp al, 0
jz test_tail03
jmp set_fruit_coordinates
test_tail03_set_y_axis:
mov test_y, -1
jmp test_tail03
test_tail03_set_x_axis:
cmp test_x,0
jz test_tail03_set_x_new_axis
dec test_x
mov al, fruit_new_x
cmp test_x, al
jz game_success
jmp test_tail03
test_tail03_set_x_new_axis:
mov test_x, 14
jmp test_tail03
; *********** set fruit coordinates
set_fruit_coordinates:
mov al, test_x
mov fruit_x, al
mov al, test_y
mov fruit_y, al
ret
wrong_tail_symbol:
lea dx, message5
mov ah, 09h
int 21h
ret
game_success:
call game_successful
ret
set_new_fruit_coordinates endp
; ************************************************************************************************************************
; ************************************************************************************************************************
; ********** test fruit new coordinates
test_fruit_new_coordinates proc near
mov al, head_x
cmp test_x, al
jnz test_with_snake_coordinates
mov al, head_y
cmp test_y, al
jnz test_with_snake_coordinates
; ********** wrong fruit new coordinates
mov al, 0
ret
test_with_snake_coordinates:
mov loop_data, 0
push di
lea di, snake1
test_fruit_new_coordinates_loop:
mov al, [ di ]
cmp test_x, al
jnz test_fruit_move_3
inc di
mov al, [ di ]
cmp test_y, al
jnz test_fruit_move_2
; ********** wrong fruit new coordinates
mov al, 0
pop di
ret
test_fruit_move_3:
add di, 3
jmp loop_data_add_1
test_fruit_move_2:
add di, 2
jmp loop_data_add_1
loop_data_add_1:
inc loop_data
mov al, num
cmp loop_data, al
jnz test_fruit_new_coordinates_loop
; ********** right fruit new coordinates
mov al, 1
pop di
ret
test_fruit_new_coordinates endp
; ************************************************************************************************************************
; ************************************************************************************************************************
; ********** set new neck coordinates and show the neck picture and show the head picture
set_new_neck_coordinates proc near
; ********** judge whether head symbol is head00 or not
cmp_head00:
mov al, 10h
cmp head_z, al
jnz cmp_head01
set_neck_coordinates1:
; ********** show head
mov al, head_x
mov show_x, al
mov al, head_y
mov show_y, al
lea si, head00
call show_graph
mov al, neck_x
inc al
cmp head_x, al
ja head00_neck_x_add_1
mov al, neck_y
cmp head_y, al
ja head00_neck_y_add_1
dec neck_y
mov neck_z, 20h
lea si, neck00
mov al, neck_x
mov show_x, al
mov al, neck_y
mov show_y, al
call show_graph
ret
head00_neck_x_add_1:
inc neck_x
mov neck_z, 40h
lea si, level
mov al, neck_x
mov show_x, al
mov al, neck_y
mov show_y, al
call show_graph
ret
head00_neck_y_add_1:
inc neck_y
mov neck_z, 23h
lea si, neck03
mov al, neck_x
mov show_x, al
mov al, neck_y
mov show_y, al
call show_graph
ret
; ********** judge whether head symbol is head01 or not
cmp_head01:
mov al, 11h
cmp head_z, al
jnz cmp_head02
set_neck_coordinates2:
; ********** show head
mov al, head_x
mov show_x, al
mov al, head_y
mov show_y, al
lea si, head01
call show_graph
mov al, neck_y
inc al
cmp head_y, al
ja head01_neck_y_add_1
mov al, neck_x
cmp head_x, al
ja head01_neck_x_add_1
dec neck_x
mov neck_z, 20h
lea si, neck00
mov al, neck_x
mov show_x, al
mov al, neck_y
mov show_y, al
call show_graph
ret
head01_neck_y_add_1:
inc neck_y
mov neck_z, 41h
lea si, erect
mov al, neck_x
mov show_x, al
mov al, neck_y
mov show_y, al
call show_graph
ret
head01_neck_x_add_1:
inc neck_x
mov neck_z, 21h
lea si, neck01
mov al, neck_x
mov show_x, al
mov al, neck_y
mov show_y, al
call show_graph
ret
; ********** judge whether head symbol is head02 or not
cmp_head02:
mov al, 12h
cmp head_z, al
jnz cmp_head03
set_neck_coordinates3:
; ********** show head
mov al, head_x
mov show_x, al
mov al, head_y
mov show_y, al
lea si, head02
call show_graph
mov al, neck_x
dec al
cmp head_x, al
jb head02_neck_x_dec_1
mov al, neck_y
cmp head_y, al
ja head02_neck_y_add_1
dec neck_y
mov neck_z, 21h
lea si, neck01
mov al, neck_x
mov show_x, al
mov al, neck_y
mov show_y, al
call show_graph
ret
head02_neck_y_add_1:
inc neck_y
mov neck_z, 22h
lea si, neck02
mov al, neck_x
mov show_x, al
mov al, neck_y
mov show_y, al
call show_graph
ret
head02_neck_x_dec_1:
dec neck_x
mov neck_z, 40h
lea si, level
mov al, neck_x
mov show_x, al
mov al, neck_y
mov show_y, al
call show_graph
ret
; ********** judge whether head symbol is head03 or not
cmp_head03:
mov al, 13h
cmp head_z, al
jnz wrong_neck
set_neck_coordinates4:
; ********** show head
mov al, head_x
mov show_x, al
mov al, head_y
mov show_y, al
lea si, head03
call show_graph
mov al, neck_y
dec al
cmp head_y, al
jb head03_neck_y_dec_1
mov al, neck_x
cmp head_x, al
ja head03_neck_x_add_1
dec neck_x
mov neck_z, 23h
lea si, neck03
mov al, neck_x
mov show_x, al
mov al, neck_y
mov show_y, al
call show_graph
ret
head03_neck_y_dec_1:
dec neck_y
mov neck_z, 41h
lea si, erect
mov al, neck_x
mov show_x, al
mov al, neck_y
mov show_y, al
call show_graph
ret
head03_neck_x_add_1:
inc neck_x
mov neck_z, 22h
lea si, neck02
mov al, neck_x
mov show_x, al
mov al, neck_y
mov show_y, al
call show_graph
ret
wrong_neck:
lea dx, message3
mov ah, 09h
int 21h
ret
set_new_neck_coordinates endp
; ************************************************************************************************************************
; ************************************************************************************************************************
; ********** move one position
move_one proc near
; ********** set snake tail new coordinates and its picture
call set_new_tail_coordinates
; ********** set snake neck new coordinates and its picture
call set_new_neck_coordinates
; ********** show the fruit
mov al, fruit_x
mov show_x, al
mov al, fruit_y
mov show_y, al
lea si, fruit
call show_graph
; ********** change snake tail position into blank
lea di, snake1
mov al, [ di ]
mov show_x, al
inc di
mov al, [ di ]
mov show_y, al
lea si, blank
call show_graph
; ********** set snake new coordinates
lea si, snake1
add si, 3
; ********** set snake2 new coordinates
push cx
lea di, snake2
mov al, num
mov al, 3
mul num
mov cx, ax
sub cx, 3
cld
rep movsb
lea di, snake2
mov al, num
mov x, al
dec x
mov al, 3
mul x
add di, ax
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -