⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 game.asm

📁 本程序是一个全汇编语言设计的小型游戏.它的功能是: 设法引导贪食蛇吃掉果实以使得它变的更长!
💻 ASM
📖 第 1 页 / 共 5 页
字号:
.model small
.386
.stack

.data
color_index_list db 256 dup ( 3 dup ( ? ) ) ; color index list
snake1 db 120 dup ( 3 dup ( ? ) ) ; snake coordinates
snake2 db 120 dup ( 3 dup ( ? ) ) ; snake copy coordinates
head_x db 0    ; snake head X coordinates
head_y db 0    ; snake head Y coordinates
head_z db 0    ; snake head symbol
neck_x db 0    ; snake neck X coordinates
neck_y db 0    ; snake neck Y coordinates
neck_z db 0    ; snake neck symbol
fruit_x db 0    ; fruit X coordinates
fruit_y db 0    ; fruit Y coordintes
fruit_new_x db 0    ; fruit new X coordinates
fruit_new_y db 0    ; fruit new Y coordinates 
fruit_z db 43h    ; fruit symbol
show_x db 0    ; show X coordinate
show_y db 0    ; show Y coordinate
show_z db 0    ; show symbol
buffer_x db 0    ; snake buffer X coordinates
buffer_y db 0    ; snake buffer Y coordinates
buffer_z db 0    ; snake buffer symbol
test_x db 0    ; test X coordinates
test_y db 0    ; test Y coordinates
test_z db 0    ; test symbol
achievement dw 0    ; game achievement
max_achievement dw 20   ; the largest game achievement
grade db 1    ; game grade
new_grade db 1    ; game new grade

background_file_name db 'back.bmp', 00    ; background file name
menu_file_name db 'menu.bmp', 00    ; menu file name
grade_file_name db 'grade.bmp', 00    ; grade file name
gradesetting_file_name db 'gradeset.bmp', 00    ; gradesetting file name
gameend_file_name db 'gameend.bmp', 00    ; gameend file name
intro_file_name db 'intro.bmp', 00    ; intro file name
snake_file_name db 'snake.bmp', 00    ; snake file name
data1_file_name db 'data1.bmp', 00    ; data1 file name
data2_file_name db 'data2.bmp', 00    ; data2 file name
success_file_name db 'success.bmp', 00    ; success file name
head00 db 400 dup ( ? )    ; no.1 head data
head01 db 400 dup ( ? )    ; no.2 head data
head02 db 400 dup ( ? )    ; no.3 head data
head03 db 400 dup ( ? )    ; no.4 head data
neck00 db 400 dup ( ? )    ; no.1 neck data
neck01 db 400 dup ( ? )    ; no.2 neck data
neck02 db 400 dup ( ? )    ; no.3 neck data
neck03 db 400 dup ( ? )    ; no.4 neck data
tail00 db 400 dup ( ? )    ; no.1 tail data
tail01 db 400 dup ( ? )    ; no.2 tail data
tail02 db 400 dup ( ? )    ; no.3 tail data
tail03 db 400 dup ( ? )    ; no.4 tail data
level db 400 dup ( ? )     ; level data
erect db 400 dup ( ? )     ; erect data
blank db 400 dup ( ? )     ; blank data 
fruit db 400 dup ( ? )     ; fruit data
data1_1 db 140 dup ( ? )    ; data1_1 data
data1_2 db 140 dup ( ? )    ; data1_2 data
data1_3 db 140 dup ( ? )    ; data1_3 data
data1_4 db 140 dup ( ? )    ; data1_4 data
data1_5 db 140 dup ( ? )    ; data1_5 data
data1_6 db 140 dup ( ? )    ; data1_6 data
data1_7 db 140 dup ( ? )    ; data1_7 data
data1_8 db 140 dup ( ? )    ; data1_8 data
data1_9 db 140 dup ( ? )    ; data1_9 data
data1_0 db 140 dup ( ? )    ; data1_0 data
data2_1 db 280 dup ( ? )    ; data2_1 data
data2_2 db 280 dup ( ? )    ; data2_2 data
data2_3 db 280 dup ( ? )    ; data2_3 data
data2_4 db 280 dup ( ? )    ; data2_4 data
data2_5 db 280 dup ( ? )    ; data2_5 data
grade1 db 2000 dup ( ? )    ; grade1 data
grade2 db 2000 dup ( ? )    ; grade2 data
grade3 db 2000 dup ( ? )    ; grade3 data
grade4 db 2000 dup ( ? )    ; grade4 data
grade5 db 2000 dup ( ? )    ; grade5 data
show_row db 320 dup ( ? )  ; show row data
data_buffer db 00,00,00,00 ; data buffer
file_symbol dw 00h          ; file symbol

x db 0h
y dw 0h
z dw 0h
sound_data dw 300ch    ; sound data
num db 2    ; the whole snake number
loop_data db 0

new_game_string db 'n. new game' , 0dh, 0ah, '$'    ; 11 char
grade_string db 'g. grade', 0dh, 0ah, '$'    ; 8 char
intro_game_string db 'i. game intro', 0dh, 0ah, '$'    ; 13 char
exit_game db 'e. exit game', 0dh, 0ah, '$'    ; 12 char
finally_picture db 'f. finally picture', 0dh, 0ah, '$'    ; 18 char
largest_achievement db 'l. largest game', 0dh, 0ah, '$'    ; 15 char
input_your_choice db 'choice:     ', 0dh, 0ah, '$'    ; 12 char
input_wrong_string db 'wrong input!', 0dh, 0ah, '$'    ; 12 char

msg10 db 'menu file open success!!',0dh,0ah,'$'
msg11 db 'menu file open fail!!',0dh,0ah,'$'
msg20 db 'background file open success!!',0dh,0ah,'$'
msg21 db 'background file open fail!!',0dh,0ah,'$'
msg30 db 'snake file open success!!',0dh,0ah,'$'
msg31 db 'snake file open fail!!',0dh,0ah,'$'
msg40 db 'gradesetting file open success!!',0dh,0ah,'$'
msg41 db 'gradesetting file open fail!!',0dh,0ah,'$'
msg50 db 'gameend file open success!!',0dh,0ah,'$'
msg51 db 'gameend file open fail!!',0dh,0ah,'$'
msg60 db 'intro file open success!!',0dh,0ah,'$'
msg61 db 'intro file open fail!!',0dh,0ah,'$'
msg70 db 'grade file open success!!',0dh,0ah,'$'
msg71 db 'grade file open fail!!',0dh,0ah,'$'
msg80 db 'data1 file open success!!',0dh,0ah,'$'
msg81 db 'data1 file open fail!!',0dh,0ah,'$'
msg90 db 'data2 file open success!!',0dh,0ah,'$'
msg91 db 'data2 file open fail!!',0dh,0ah,'$'
msg100 db 'success file open success!!',0dh,0ah,'$'
msg101 db 'success file open fail!!',0dh,0ah,'$'
message2 db 'wrong head symbol!!',0dh,0ah,'$'
message3 db 'wrong neck symbol!!',0dh,0ah,'$'
message4 db 'wrong fruit symbol!!',0dh,0ah,'$'
message5 db 'wrong tail symbol!!',0dh,0ah,'$'
message6 db 'game success!!',0dh,0ah,'$'
message7 db 'wrong snake[2] symbol!!',0dh,0ah,'$'
message8 db 'GAME OVER!',0dh,0ah,'$'

.code

; ************************************************************************************************************************
; ************************************************************************************************************************
main proc far
    mov ax, @data
    mov ds, ax
    mov es, ax

    mov ax, 0002h
    int 10h

; **********test the menu file
test_menu_file:
    lea dx, menu_file_name
    mov cx, 0h
    mov ah, 4eh
    int 21h
    jc open_menu_fail
open_menu_success:
    lea dx, msg10
    mov ah, 09h
    int 21h
    jmp test_background_file
open_menu_fail:
    lea dx, msg11
    mov ah, 09h
    int 21h
    jmp exit

; **********test the background file
test_background_file:
    lea dx, background_file_name
    mov cx, 0h
    mov ah, 4eh
    int 21h
    jc open_background_fail
open_background_success:
    lea dx, msg20
    mov ah, 09h
    int 21h
    jmp test_snake_file
open_background_fail:
    lea dx, msg21
    mov ah, 09h
    int 21h
    jmp exit

; **********test the snake file
test_snake_file:
    lea dx, snake_file_name
    mov cx, 0h
    mov ah, 4eh
    int 21h
    jc open_snake_fail
open_snake_success:
    lea dx, msg30
    mov ah, 09h
    int 21h
    jmp test_gradesetting_file
open_snake_fail:
    lea dx, msg31
    mov ah, 09h
    int 21h
    jmp exit

; **********test the gradesetting file
test_gradesetting_file:
    lea dx, gradesetting_file_name
    mov cx, 0h
    mov ah, 4eh
    int 21h
    jc open_gradesetting_fail
open_gradesetting_success:
    lea dx, msg40
    mov ah, 09h
    int 21h
    jmp test_gameend_file
open_gradesetting_fail:
    lea dx, msg41
    mov ah, 09h
    int 21h
    jmp exit

; **********test the gameend file
test_gameend_file:
    lea dx, gameend_file_name
    mov cx, 0h
    mov ah, 4eh
    int 21h
    jc open_gameend_fail
open_gameend_success:
    lea dx, msg50
    mov ah, 09h
    int 21h
    jmp test_intro_file
open_gameend_fail:
    lea dx, msg51
    mov ah, 09h
    int 21h
    jmp exit

; **********test the intro file
test_intro_file:
    lea dx, intro_file_name
    mov cx, 0h
    mov ah, 4eh
    int 21h
    jc open_intro_fail
open_intro_success:
    lea dx, msg60
    mov ah, 09h
    int 21h
    jmp test_grade_file
open_intro_fail:
    lea dx, msg61
    mov ah, 09h
    int 21h
    jmp exit

; **********test the grade file
test_grade_file:
    lea dx, grade_file_name
    mov cx, 0h
    mov ah, 4eh
    int 21h
    jc open_grade_fail
open_grade_success:
    lea dx, msg70
    mov ah, 09h
    int 21h
    jmp test_data1_file
open_grade_fail:
    lea dx, msg71
    mov ah, 09h
    int 21h
    jmp exit

; **********test the data1 file
test_data1_file:
    lea dx, data1_file_name
    mov cx, 0h
    mov ah, 4eh
    int 21h
    jc open_data1_fail
open_data1_success:
    lea dx, msg80
    mov ah, 09h
    int 21h
    jmp test_data2_file
open_data1_fail:
    lea dx, msg81
    mov ah, 09h
    int 21h
    jmp exit

; **********test the data2 file
test_data2_file:
    lea dx, data2_file_name
    mov cx, 0h
    mov ah, 4eh
    int 21h
    jc open_data2_fail
open_data2_success:
    lea dx, msg90
    mov ah, 09h
    int 21h
    jmp test_success_file
open_data2_fail:
    lea dx, msg91
    mov ah, 09h
    int 21h
    jmp exit


; **********test the success file
test_success_file:
    lea dx, success_file_name
    mov cx, 0h
    mov ah, 4eh
    int 21h
    jc open_success_fail
open_success_success:
    lea dx, msg100
    mov ah, 09h
    int 21h
    jmp get_data
open_success_fail:
    lea dx, msg101
    mov ah, 09h
    int 21h
    jmp exit

get_data:
    call wait_time

; ********** set video to 320*200  graph
    mov al,13h
    mov ah,0h
    int 10h
    lea dx, menu_file_name
    mov al, 0
    mov ah, 3dh
    int 21h
    mov file_symbol, ax    ; get the menu file symbol
    call get_color_index_list    ; get the color index list
    call get_snake_picture_data    ; get the snake picture data and the fruit picture data
    call get_data1_picture_data    ; get the data1 picture data 
    call get_data2_picture_data    ; get the data2 picture data 

    call menu    ; show the menu file

exit:
; **********exit program
    mov ax, 0002h
    int 10h
    mov ax, 4c00h
    int 21h
    ret
main endp


; ************************************************************************************************************************
; ************************************************************************************************************************
; **********  menu  
menu proc near
    lea dx, menu_file_name
    mov al, 0
    mov ah, 3dh
    int 21h
    mov file_symbol, ax    ; get the background 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 show_string 
    call read_key

    call close_file    ; close the background file
    ret
menu endp


; ************************************************************************************************************************
; ************************************************************************************************************************
; ********** show string
show_string proc near
   push es
   mov al, 0
   lea bp, new_game_string
   mov cx, 11
   mov dh, 12
   mov dl, 14
   mov ah, 13h
   int 10h
   lea bp, grade_string
   mov cx, 8
   add dh, 2
   mov dl, 14
   mov ah, 13h
   int 10h
   lea bp, intro_game_string
   mov cx, 13
   add dh, 2
   mov dl, 14
   mov ah, 13h
   int 10h
   lea bp, exit_game
   mov cx, 12
   add dh, 2
   mov dl, 14
   mov ah, 13h
   int 10h
   lea bp, input_your_choice
   mov cx, 12
   add dh, 3
   mov dl, 9
   mov ah, 13h
   int 10h
   


   pop es
show_string endp


; ************************************************************************************************************************
; ************************************************************************************************************************
; ********** 
read_key proc near

; ********** show string : input choice: 
    lea bp, input_your_choice
    mov al, 0
    mov cx, 12
    mov dh, 21
    mov dl, 9
    mov ah, 13h
    int 10h

    mov ah,0h
    int 16h

read:
    mov x, al
; ********** set cursor position and show input
    mov dh, 21
    mov dl, 17
    mov ah, 2
    int 10h
    mov ah, 0ah
    mov cx, 1
    int 10h

    cmp x, 65h         ; if e pressed the exit
    jnz  test_new

; ********** input char
    mov ah, 0h
    int 16h
    cmp ah, 1ch
    jnz read

; ********** exit program
    mov al,03h
    mov ah,0h
    int 10h
    mov ax, 4c00h
    int 21h 
    ret
; ********** if n pressed begin the new game
test_new:
    cmp x, 6eh
    jnz test_grade
new:

; ********** input char
    mov ah, 0h
    int 16h
    cmp ah, 1ch
    jnz read

; ********** show background
    call show_background_file    ; show the background file
    call new_game
    jmp read

; ********** if g pressed set the grade of the game
test_grade:
    cmp x, 67h
    jnz test_intro

; ********** input char
    mov ah, 0h
    int 16h
    cmp ah, 1ch
    jnz read

    call get_grade_picture_data
    call set_grade
    jmp read

; ********** if i pressed intro the game
test_intro:
    cmp x, 69h
    jnz read_key_input_wrong
left:
; ********** input char
    mov ah, 0h
    int 16h
    cmp ah, 1ch
    jnz read

    call show_intro          
    jmp read

; ********* dispose wrong input
read_key_input_wrong:
    mov al, 0
    lea bp, input_wrong_string
    mov cx, 12
    mov dh, 21
    mov dl, 9
    mov ah, 13h
    int 10h

    call wait_time
; ********** show string : input choice: 
    lea bp, input_your_choice
    mov al, 0
    mov cx, 12
    mov dh, 21
    mov dl, 9
    mov ah, 13h
    int 10h

    mov ah, 0h
    int 16h

    jmp read

     ret    
read_key endp

; ************************************************************************************************************************
; ************************************************************************************************************************
; ********** show the background file 
show_background_file proc near
    lea dx, background_file_name
    mov al, 0
    mov ah, 3dh
    int 21h
    mov file_symbol, ax    ; get the background 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 background file
    ret
show_background_file endp

; ************************************************************************************************************************
; ************************************************************************************************************************
; ********** get color index list

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -