📄 game.asm
字号:
get_color_index_list proc near
; ********** remove the file pointer to the index list
mov bx, file_symbol
mov cx, 0
mov dx, 54
mov al, 1
mov ah, 42h
int 21h
; ********** transport the data
mov bx, file_symbol
lea di, color_index_list
lea dx, data_buffer
mov cx, 256
transport_data:
; ********** read 4 byte from the opened file
push cx
mov cx, 4
mov al, 0h
mov ah, 3fh
int 21h
pop cx
mov si, dx
; ********** processing red table
mov al, [ si + 2 ]
shr al, 2
mov [ di ] , al
inc di
; ********** processing green table
mov al, [ si + 1 ]
shr al, 2
mov [ di ] , al
inc di
; ********** processing blue table
mov al, [ si + 0 ]
shr al, 2
mov [ di ] , al
inc di
loop transport_data
; ********** set the video card color table
lea dx, color_index_list
mov bx, 0
mov cx,256
mov al,12h
mov ah,10h
int 10h
ret
get_color_index_list endp
; ************************************************************************************************************************
; ************************************************************************************************************************
; ********** read picture data
show_picture proc near
push es
mov ax, 0a000h
mov es, ax
mov di, 0
mov cx, 200
cld ; direction flag = 0
; ********** invert the picture data
read_data:
mov bx, cx
dec bx
mov ax, 320
mul bx
mov di, ax
push cx
mov cx, 320
lea si, show_row
lea dx, show_row
mov bx, file_symbol
mov ax, 3f00h
int 21h
mov cx, 320
rep movsb
pop cx
loop read_data
pop es
ret
show_picture endp
; ************************************************************************************************************************
; ************************************************************************************************************************
; ********** run the new game
new_game proc near
mov num, 2
mov achievement, 0
mov al, new_grade
mov grade, al
new_snake:
lea di, snake1
; ********** set snake tail coordinates
mov al, 0
mov [ di ], al
inc di
mov al, 4
mov [ di ], al
inc di
mov al, 31h
mov [ di ], al
inc di
; ********** set snake neck coordinates
mov neck_x, 0
mov neck_y, 5
mov neck_z, 23h
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 di
; ********** set snake head coordinates
mov head_x, 1
mov head_y, 5
mov head_z, 10h
mov al, head_x
mov [ di ], al
inc di
mov al, head_y
mov [ di ], al
inc di
mov al, head_z
mov [ di ], al
inc dx
set_fruit:
; ********** set fruit coordinates
mov fruit_x, 8
mov fruit_y, 3
; *********** show the achievement ,max_achievement and grade
call show_achievement
call show_max_achievement
call show_grade
show_new_snake:
; ********** show snake tail
mov show_x, 0
mov show_y, 5
lea si, tail01
call show_graph
mov al,neck_x
mov show_x, al
mov al,neck_y
mov show_y, al
lea si, neck03
call show_graph
mov al, head_x
mov show_x, al
mov al, head_y
mov show_y, al
lea si, head00
call show_graph
show_fruit:
; ********** show fruit
mov al, fruit_x
mov show_x, al
mov al, fruit_y
mov show_y, al
lea si, fruit
call show_graph
; ********** set new head coordinate
inc head_x
call dispose_new_coordinate
ret
new_game endp
; ************************************************************************************************************************
; ************************************************************************************************************************
; ********** get the grade picture data
get_grade_picture_data proc near
lea dx, grade_file_name
mov ah, 3dh
mov al, 0h
int 21h
mov file_symbol, ax
; ********** set the file pointer to the first picture data
mov bx, file_symbol
mov cx, 0
mov dx, 1078 ; set mov offset number
mov ax, 4201h
int 21h
; ********** get the data from grade1 to grade5
get_grade5:
lea dx, grade5
mov cx, 2000
mov ax, 3f00h
int 21h
get_grade4:
lea dx, grade4
mov cx, 2000
mov ax, 3f00h
int 21h
get_grade3:
lea dx, grade3
mov cx, 2000
mov ax, 3f00h
int 21h
get_grade2:
lea dx, grade2
mov cx, 2000
mov ax, 3f00h
int 21h
get_grade1:
lea dx, grade1
mov cx, 2000
mov ax, 3f00h
int 21h
; ********** close the file
call close_file
ret
get_grade_picture_data endp
; ************************************************************************************************************************
; ************************************************************************************************************************
; ********** set grade
set_grade proc near
; ********** show gradesetting.bmp
lea dx, gradesetting_file_name
mov al, 0
mov ah, 3dh
int 21h
mov file_symbol, ax ; get the gradesetting file symbol
; ********** set the file pointer to the first picture data
mov bx, file_symbol
mov cx, 0
mov dx, 1078 ; set mov offset number
mov ax, 4201h
int 21h
call show_picture ; read the picture data from the file and transport them to the video buffer
call close_file ; close the gradesetting file
; ********** set cursor position
cmp new_grade, 3
jb set_grade_1_2 ; if grade < 3 then goto set_grade_1_2
cmp new_grade, 4
jb set_grade_3 ; if grade < 4 then goto set_grade_3
cmp new_grade, 4
jz set_grade_4 ; if grade = 4 then goto set_grade_4
lea si, grade5
jmp show_old_grade
set_grade_4:
lea si, grade4
jmp show_old_grade
set_grade_3:
lea si, grade3
jmp show_old_grade
set_grade_1_2:
cmp new_grade, 2
jnz set_grade_1 ; if grade != 2 then goto set_grade_1
lea si, grade2
jmp show_old_grade
set_grade_1:
lea si, grade1
show_old_grade:
mov z, 25700
mov y, 20
mov x, 100
call show_data
lea bp, input_your_choice
mov al, 0
mov cx, 12
mov dh, 15
mov dl, 13
mov ah, 13h
int 10h
mov dh, 15
mov dl, 21
mov ah, 2
int 10h
mov ah, 0h
int 16h
test_1:
cmp al, 31h ; if 1 pressed set grade 1
jnz test_2
; ********** show input
mov ah, 0ah
mov cx, 1
int 10h
; ********** show grade1
lea si, grade1
mov z, 25700
mov y, 20
mov x, 100
call show_data
; ********** input char
mov ah, 0h
int 16h
cmp ah, 1ch
jnz test_1
mov new_grade, 1
jmp set_grade_show
test_2:
cmp al, 32h ; if 2 pressed set grade 2
jnz test_3
; ********** show input
mov ah, 0ah
mov cx, 1
int 10h
; ********** show grade2
lea si, grade2
mov z, 25700
mov y, 20
mov x, 100
call show_data
; ********** input char
mov ah, 0h
int 16h
cmp ah, 1ch
jnz test_1
mov new_grade, 2
jmp set_grade_show
test_3:
cmp al, 33h ; if 3 pressed set grade 3
jnz test_4
; ********** show input
mov ah, 0ah
mov cx, 1
int 10h
; ********** show grade3
lea si, grade3
mov z, 25700
mov y, 20
mov x, 100
call show_data
; ********** input char
mov ah, 0h
int 16h
cmp ah, 1ch
jnz test_1
mov new_grade, 3
jmp set_grade_show
test_4:
cmp al, 34h ; if 4 pressed set grade 4
jnz test_5
; ********** show input
mov ah, 0ah
mov cx, 1
int 10h
; ********** show grade4
lea si, grade4
mov z, 25700
mov y, 20
mov x, 100
call show_data
; ********** input char
mov ah, 0h
int 16h
cmp ah, 1ch
jnz test_1
mov new_grade, 4
jmp set_grade_show
test_5:
cmp al, 35h ; if 5 pressed set grade 5
jnz test_enter
; ********** show input
mov ah, 0ah
mov cx, 1
int 10h
; ********** show grade5
lea si, grade5
mov z, 25700
mov y, 20
mov x, 100
call show_data
; ********** input char
mov ah, 0h
int 16h
cmp ah, 1ch
jnz test_1
mov new_grade, 5
jmp set_grade_show
test_enter:
mov al, 0
lea bp, input_wrong_string
mov cx, 12
mov dh, 15
mov dl, 13
mov ah, 13h
int 10h
call wait_time
lea bp, input_your_choice
mov al, 0
mov cx, 12
mov dh, 15
mov dl, 13
mov ah, 13h
int 10h
; ********** input char
mov ah, 0h
int 16h
jmp test_1
set_grade_show:
call menu
ret
set_grade endp
; ************************************************************************************************************************
; ************************************************************************************************************************
; ********** show intro
show_intro proc near
; ********** show menu picture
lea dx, intro_file_name
mov al, 0
mov ah, 3dh
int 21h
mov file_symbol, ax ; get the gameend file symbol
; ********** set the file pointer to the first picture data
mov bx, file_symbol
mov cx, 0
mov dx, 1078 ; set mov offset number
mov ax, 4201h
int 21h
call show_picture ; read the picture data from the file and transport them to the video buffer
show_intro_read_key:
mov ah, 1h
int 16h
jz show_intro_read_key
call menu
ret
show_intro endp
; ************************************************************************************************************************
; ************************************************************************************************************************
; ********** get the snake picture data
get_snake_picture_data proc near
lea dx, snake_file_name
mov ah, 3dh
mov al, 0h
int 21h
mov file_symbol, ax
; ********** set the file pointer to the first picture data
mov bx, file_symbol
mov cx, 0
mov dx, 1078 ; set mov offset number
mov ax, 4201h
int 21h
; ********** get fruit, blank, erect, level picture data
get_fruit_blank_erect_level:
lea dx, level
mov al, 20
mul loop_data
add dx, ax
mov bx, file_symbol
mov cx, 20
mov ah, 3fh
int 21h
lea dx, erect
mov al, 20
mul loop_data
add dx, ax
mov bx, file_symbol
mov cx, 20
mov ah, 3fh
int 21h
lea dx, blank
mov al, 20
mul loop_data
add dx, ax
mov bx, file_symbol
mov cx, 20
mov ah, 3fh
int 21h
lea dx, fruit
mov al, 20
mul loop_data
add dx, ax
mov bx, file_symbol
mov cx, 20
mov ah, 3fh
int 21h
inc loop_data
cmp loop_data, 20
jnz get_fruit_blank_erect_level
; ********** get tail picture data
mov loop_data, 0
get_tail:
lea dx, tail00
mov al, 20
mul loop_data
add dx, ax
mov bx, file_symbol
mov cx, 20
mov ah, 3fh
int 21h
lea dx, tail01
mov al, 20
mul loop_data
add dx, ax
mov bx, file_symbol
mov cx, 20
mov ah, 3fh
int 21h
lea dx, tail02
mov al, 20
mul loop_data
add dx, ax
mov bx, file_symbol
mov cx, 20
mov ah, 3fh
int 21h
lea dx, tail03
mov al, 20
mul loop_data
add dx, ax
mov bx, file_symbol
mov cx, 20
mov ah, 3fh
int 21h
inc loop_data
cmp loop_data, 20
jnz get_tail
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -