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

📄 game.asm

📁 本程序是一个全汇编语言设计的小型游戏.它的功能是: 设法引导贪食蛇吃掉果实以使得它变的更长!
💻 ASM
📖 第 1 页 / 共 5 页
字号:
; ********** get neck picture data
    mov loop_data, 0
get_neck:
    lea dx, neck00
    mov al, 20
    mul loop_data
    add dx, ax 
    mov bx, file_symbol
    mov cx, 20
    mov ah, 3fh
    int 21h
 
    lea dx, neck01
    mov al, 20
    mul loop_data
    add dx, ax
    mov bx, file_symbol
    mov cx, 20
    mov ah, 3fh
    int 21h

    lea dx, neck02
    mov al, 20
    mul loop_data
    add dx, ax
    mov bx, file_symbol
    mov cx, 20
    mov ah, 3fh
    int 21h

    lea dx, neck03
    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_neck

; ********** get head picture data
    mov loop_data, 0
get_head:
    lea dx, head00
    mov al, 20
    mul loop_data
    add dx, ax 
    mov bx, file_symbol
    mov cx, 20
    mov ah, 3fh
    int 21h
 
    lea dx, head01
    mov al, 20
    mul loop_data
    add dx, ax
    mov bx, file_symbol
    mov cx, 20
    mov ah, 3fh
    int 21h

    lea dx, head02
    mov al, 20
    mul loop_data
    add dx, ax
    mov bx, file_symbol
    mov cx, 20
    mov ah, 3fh
    int 21h

    lea dx, head03
    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_head
    
    call close_file
    ret
get_snake_picture_data endp

; ************************************************************************************************************************
; ************************************************************************************************************************
; ********** get the data1 picture data  
get_data1_picture_data proc near
    lea dx, data1_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 data1_1 to data1_0 
    mov loop_data, 0   
get_data1:

    lea dx, data1_1
    mov al, 10
    mul loop_data
    add dx, ax 
    mov bx, file_symbol
    mov cx, 10
    mov ah, 3fh
    int 21h
 
    lea dx, data1_2
    mov al, 10
    mul loop_data
    add dx, ax
    mov bx, file_symbol
    mov cx, 10
    mov ah, 3fh
    int 21h

    lea dx, data1_3
    mov al, 10
    mul loop_data
    add dx, ax
    mov bx, file_symbol
    mov cx, 10
    mov ah, 3fh
    int 21h

    lea dx, data1_4
    mov al, 10
    mul loop_data
    add dx, ax
    mov bx, file_symbol
    mov cx, 10
    mov ah, 3fh
    int 21h
    
    lea dx, data1_5
    mov al, 10
    mul loop_data
    add dx, ax
    mov bx, file_symbol
    mov cx, 10
    mov ah, 3fh
    int 21h
 
    lea dx, data1_6
    mov al, 10
    mul loop_data
    add dx, ax
    mov bx, file_symbol
    mov cx, 10
    mov ah, 3fh
    int 21h

    lea dx, data1_7
    mov al, 10
    mul loop_data
    add dx, ax
    mov bx, file_symbol
    mov cx, 10
    mov ah, 3fh
    int 21h

    lea dx, data1_8
    mov al, 10
    mul loop_data
    add dx, ax
    mov bx, file_symbol
    mov cx, 10
    mov ah, 3fh
    int 21h

    lea dx, data1_9
    mov al, 10
    mul loop_data
    add dx, ax
    mov bx, file_symbol
    mov cx, 10
    mov ah, 3fh
    int 21h

    lea dx, data1_0
    mov al, 10
    mul loop_data
    add dx, ax
    mov bx, file_symbol
    mov cx, 10
    mov ah, 3fh
    int 21h  
    inc loop_data
    cmp loop_data, 14
    jnz get_data1

; ********** close the file
    call close_file
    ret
get_data1_picture_data endp

; ************************************************************************************************************************
; ************************************************************************************************************************
; ********** get the data2 picture data  
get_data2_picture_data proc near
    lea dx, data2_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 data1_1 to data1_0 
    mov loop_data, 0  
get_data2:
    lea dx, data2_1
    mov al, 20
    mul loop_data
    add dx, ax 
    mov bx, file_symbol
    mov cx, 20
    mov ah, 3fh
    int 21h
 
    lea dx, data2_2
    mov al, 20
    mul loop_data
    add dx, ax
    mov bx, file_symbol
    mov cx, 20
    mov ah, 3fh
    int 21h

    lea dx, data2_3
    mov al, 20
    mul loop_data
    add dx, ax
    mov bx, file_symbol
    mov cx, 20
    mov ah, 3fh
    int 21h

    lea dx, data2_4
    mov al, 20
    mul loop_data
    add dx, ax
    mov bx, file_symbol
    mov cx, 20
    mov ah, 3fh
    int 21h
    
    lea dx, data2_5
    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, 14
    jnz get_data2

; ********** close the file
    call close_file
    ret
get_data2_picture_data endp

; ************************************************************************************************************************
; ************************************************************************************************************************
; ********** show the user's achievement
show_achievement proc near

; ********** show 100 digit
    mov loop_data, 0    ; it mark the data is achievement or max_achievement
    
    mov ax, achievement
    mov x, 100
    div x
    mov x, al    ; x denote the data for needing to get 
    call test_achievement_data
    mov z, 50
    mov y, 14 
    mov x, 10
    call show_data
; ********** show 10 digit
    mov loop_data, 0    ; it mark the data is achievement or max_achievement
    mov ax, achievement
    mov x, 100
    div x
    shr ax, 8
    mov x, 10
    div x
    mov x, al
    call test_achievement_data
    mov z, 62
    mov y, 14
    mov x, 10
    call show_data
; ********** show 1 digit
    mov loop_data, 0    ; it mark the data is achievement or max_achievement
    mov ax, achievement
    mov x, 10
    div x
    mov x, ah
    call test_achievement_data
    mov z, 74
    mov y, 14
    mov x, 10
    call show_data

    ret
show_achievement endp

game_successful proc near
; ********** show menu picture
    lea dx, success_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
    
    call wait_time
    call menu
    ret
game_successful endp

; ************************************************************************************************************************
; ************************************************************************************************************************
; ********** show the largest achievement
show_max_achievement proc near

; ********** show 100 digit
    mov loop_data, 0    ; it mark the data is achievement or max_achievement
    
    mov ax, max_achievement
    mov x, 100
    div x
    mov x, al    ; x denote the data for needing to get 
    call test_achievement_data
    mov z, 272
    mov y, 14 
    mov x, 10
    call show_data
; ********** show 10 digit
    mov loop_data, 0    ; it mark the data is achievement or max_achievement
    mov ax, max_achievement
    mov x, 100
    div x
    shr ax, 8
    mov x, 10
    div x
    mov x, al
    call test_achievement_data
    mov z, 284
    mov y, 14
    mov x, 10
    call show_data
; ********** show 1 digit
    mov loop_data, 0    ; it mark the data is achievement or max_achievement
    mov ax, max_achievement
    mov x, 10
    div x
    mov x, ah
    call test_achievement_data
    mov z, 296
    mov y, 14
    mov x, 10
    call show_data

    ret
show_max_achievement endp


; ************************************************************************************************************************
; ************************************************************************************************************************
; ********** show grade
show_grade proc near
    mov loop_data, 1
    mov al, grade
    mov x, al
    call test_achievement_data
    mov z, 142
    mov y, 14
    mov x, 20
    call show_data

    ret
show_grade endp

; ************************************************************************************************************************
; ************************************************************************************************************************
; ********** test achievement data 
; ********** it need x var which is the data for needing to get and loop_data which is the data for judgement whether is 
; ********** achievement or grade ( 0 / 1 )
; ********** it will set si var   
test_achievement_data proc near
    cmp x, 5
    jna goto_not_above_5    ; if x <= 5 then goto not above 5
    cmp x, 7
    ja goto_above_7     ; if x > 7 then goto above 7
    cmp x, 6
    jnz goto_7    ; if x != 6 then goto 7
    lea si, data1_6
    ret
goto_7:
    lea si, data1_7
    ret
goto_above_7:
    cmp x, 8
    jnz goto_9     ; if x != 8 then goto 9
    lea si, data1_8
    ret
goto_9:
    lea si, data1_9
    ret 
goto_not_above_5:
    cmp x, 3
    jb goto_below_3    ; if x < 3 then goto below 3
    cmp x, 3
    ja goto_above_3    ; if x > 3 then goto above 3
    cmp loop_data, 0
    jnz goto_3_for_grade     ; if loop_data != 0 then goto 3 for grade
    lea si, data1_3
    ret
goto_3_for_grade:
    lea si, data2_3
    ret
goto_above_3:
    cmp x, 4
    jz goto_equal_4    ; if x = 4 then goto equal 4
    cmp loop_data, 0
    jnz goto_5_for_grade     ; if loop_data != 0 then goto 5 for grade
    lea si, data1_5
    ret
goto_5_for_grade:
    lea si, data2_5
    ret
goto_equal_4:
    cmp loop_data, 0    
    jnz goto_4_for_grade    ; if loop_data != 0 then goto 4 for grade
    lea si, data1_4
    ret
goto_4_for_grade:
    lea si, data2_4
    ret
goto_below_3:
    cmp x, 0
    ja goto_above_0     ; if x > 0 then goto above 0
    lea si, data1_0 
    ret
goto_above_0:
    cmp x, 1
    ja goto_equal_2     ; if x > 1 then goto equal 2
    cmp loop_data, 0
    jnz goto_1_for_grade    ; if loop_data != 0 then goto 1 for grade
    lea si, data1_1
    ret
goto_1_for_grade:
    lea si, data2_1
    ret
goto_equal_2:
    cmp loop_data, 0
    jnz goto_2_for_grade    ; if loop_data != 0 then goto 2 for grade
    lea si, data1_2
    ret
goto_2_for_grade:
    lea si, data2_2
    ret
test_achievement_data endp
    
; ************************************************************************************************************************
; ************************************************************************************************************************
; ********** show data   
; ********** it need si, z, x and y esc var
; ********** x * y denote picture specs  
show_data proc near
; ********** set the video card color table
    push es
    push di
    mov ax, 0a000h
    mov es, ax
    mov di, 0
    mov cx, y
    add y, 2
    cld

show_data_loop:
    dec y
    mov ax, 320
    mul y
    add ax, z
    mov di, ax

    push cx
    mov cx, 0
    mov cl, x
    rep  movsb
    pop cx
    loop show_data_loop
    pop di
    pop es
  
    ret 
show_data endp

; ************************************************************************************************************************
; ************************************************************************************************************************
; ********** dispose new coordinate
dispose_new_coordinate proc near
; ********** test whether head coordinate equal fruit coordinate or not   
test1:
    mov al, fruit_x
    cmp head_x, al
    jnz test2
    mov al, fruit_y
    cmp head_y, al
    jnz test2
    call add_one
    call check_input
    ret
; ********** test whether head coordinate equal snake any body coordinate or not 
test2:
    mov loop_data, 0
    lea di, snake1
test2_cmp:   
    mov al, [ di ]
    cmp head_x, al
    jnz test2_x_no_equal 
    inc di
    mov al, [ di ]
    cmp head_y, al
    jnz test2_y_no_equal
    jmp game_end
test2_x_no_equal:
    add di, 3

⌨️ 快捷键说明

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