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

📄 game.asm

📁 本程序是一个全汇编语言设计的小型游戏.它的功能是: 设法引导贪食蛇吃掉果实以使得它变的更长!
💻 ASM
📖 第 1 页 / 共 5 页
字号:
    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
    
; ********** set snake1 coordinates
    lea si, snake2
    lea di, snake1
    mov al, 3
    mul num
    mov cx, ax
    cld
    rep movsb
    pop cx
    ret

move_one endp

; ************************************************************************************************************************
; ************************************************************************************************************************
; ********** set new tail coordinates and show its picture
set_new_tail_coordinates proc near
; ********** get the old tail symbol and the new tail coordinates
    lea di, snake1
    add di, 2
    mov al, [ di ]
    mov show_z, al
    inc di
    mov al, [ di ]
    mov show_x, al
    inc di
    mov al, [ di ]
    mov show_y, al
    inc di
    mov al, [ di ]
    mov buffer_z, al

; ********** judge whether snake[ 2 ] symbol is neck00 or not
cmp_neck00:
    cmp buffer_z, 20h
    jnz cmp_neck01
    cmp show_z, 33h
    jnz neck00_tail01
    lea si, tail00
    mov al, 30h
    jmp show_new_tail
neck00_tail01:
    mov al, 31h
    lea si, tail01
    jmp show_new_tail
cmp_neck01:
    cmp buffer_z, 21h
    jnz cmp_neck02
    cmp show_z, 33h
    jnz neck01_tail01
    mov al, 32h
    lea si, tail02
    jmp show_new_tail
neck01_tail01:
    mov al, 31h
    lea si, tail01
    jmp show_new_tail
cmp_neck02:
    cmp buffer_z, 22h
    jnz cmp_neck03
    cmp show_z, 31h
    jnz neck02_tail03
    mov al, 32h
    lea si, tail02
    jmp show_new_tail
neck02_tail03:
    mov al, 33h
    lea si, tail03
    jmp show_new_tail
cmp_neck03:
    cmp buffer_z, 23h
    jnz cmp_level
    cmp show_z, 31h
    jnz neck03_tail03
    mov al, 30h
    lea si, tail00
    jmp show_new_tail
neck03_tail03:
    mov al, 33h
    lea si, tail03
    jmp show_new_tail
cmp_level:
    cmp buffer_z, 40h
    jnz cmp_erect
    cmp show_z, 30h
    jnz level_tail02
    mov al, 30h
    lea si, tail00
    jmp show_new_tail
level_tail02:
    mov al, 32h
    lea si, tail02
    jmp show_new_tail
cmp_erect:
    cmp buffer_z, 41h
    jnz snake_2_wrong
    cmp show_z, 31h
    jnz erect_tail03
    mov al, 31h
    lea si, tail01
    jmp show_new_tail
erect_tail03:
    mov al, 33h
    lea si, tail03
    jmp show_new_tail

snake_2_wrong:
    lea dx, message7
    mov ah, 09h
    int 21h
    ret
  
show_new_tail:
    lea di, snake1
    add di, 5
    mov [ di ] , al
    call show_graph   
    ret
set_new_tail_coordinates endp
   
; ************************************************************************************************************************
; ************************************************************************************************************************
; ********** check keyboard input
check_input proc near
; ********** test whether head symbol equal 10h or not
check_test1:
    cmp head_z, 10h
    jnz check_test2
    call dispose_10h
    call dispose_new_coordinate
    ret
; ********** test whether head symbol equal 11h or not
check_test2:
    cmp head_z, 11h
    jnz check_test3
    call dispose_11h
    call dispose_new_coordinate
    ret
; ********** test whether head symbol equal 12h or not
check_test3:
    cmp head_z, 12h
    jnz check_test4
    call dispose_12h
    call dispose_new_coordinate
    ret
; ********** test whether head symbol equal 13h or not
check_test4:
    cmp head_z, 13h
    jnz wrong_head
    call dispose_13h
    call dispose_new_coordinate
    ret
wrong_head:
    lea dx, message2
    mov ah, 09h
    int 21h
    
    ret
check_input endp

; ************************************************************************************************************************
; ************************************************************************************************************************
; ********** dispose the action of the snake
dispose_10h proc near
    call set_wait_time
    mov ah, x
head00_cmp_up:
    cmp ah, 48h
    jnz head00_cmp_down
    dec head_y
    mov head_z, 13h
    ret
head00_cmp_down:
    cmp ah, 50h
    jnz head00_move_one
    inc head_y
    mov head_z, 11h
    ret
head00_move_one:
    inc head_x
    ret
dispose_10h endp

; ************************************************************************************************************************
; ************************************************************************************************************************
dispose_11h proc near
    call set_wait_time
    mov ah, x
head01_cmp_left:
    cmp ah, 4bh
    jnz head01_cmp_right
    dec head_x
    mov head_z, 12h
    ret
head01_cmp_right:
    cmp ah, 4dh
    jnz head01_move_one
    inc head_x
    mov head_z, 10h
    ret
head01_move_one:
    inc head_y
    ret

dispose_11h endp

; ************************************************************************************************************************
; ************************************************************************************************************************
dispose_12h proc near
    call set_wait_time
    mov ah, x
head02_cmp_up:
    cmp ah, 48h
    jnz head02_cmp_down
    dec head_y
    mov head_z, 13h
    ret
head02_cmp_down:
    cmp ah, 50h
    jnz head02_move_one
    inc head_y
    mov head_z, 11h
    ret
head02_move_one:
    dec head_x
    ret

dispose_12h endp

; ************************************************************************************************************************
; ************************************************************************************************************************
dispose_13h proc near
    call set_wait_time
    mov ah, x
head03_cmp_left:
    cmp ah, 4bh
    jnz head03_cmp_right
    dec head_x
    mov head_z, 12h
    ret
head03_cmp_right:
    cmp ah, 4dh
    jnz head03_move_one
    inc head_x
    mov head_z, 10h
    ret
head03_move_one:
    dec head_y
    ret

dispose_13h endp

; ************************************************************************************************************************


; ************************************************************************************************************************
; ************************************************************************************************************************
; ********** set wait time
set_wait_time proc near
    push ax
    push cx
    mov loop_data, 6
    mov al, grade
    sub loop_data, al
back:
    mov cx, 33144   
waitf1:
    in al, 61h
    and al, 10h    ; check PB4
    cmp al, ah    ; did it just change
    je waitf1    ; wait for change
    mov ah, al    ; save the new PB4 status
    loop waitf1    ; continue until CX becomes 0
    mov ax, 0100h
    int 16h
    jnz interrupt
    dec loop_data
    jnz back
    mov x, 0
    jmp time_out
interrupt:
    mov ah ,0h
    int 16h
    mov x, ah
time_out:
    pop cx
    pop ax
    ret

set_wait_time endp

; ************************************************************************************************************************
; ************************************************************************************************************************
; ********** wait time
wait_time proc near
    push ax
    push cx
    mov loop_data, 10
wait_back:
    mov cx, 33144   
wait_loop:
    in al, 61h
    and al, 10h    ; check PB4
    cmp al, ah    ; did it just change
    je wait_loop    ; wait for change
    mov ah, al    ; save the new PB4 status
    loop wait_loop    ; continue until CX becomes 0
    dec loop_data
    jnz wait_back
    pop cx
    pop ax
    ret

wait_time endp

; ************************************************************************************************************************
; ************************************************************************************************************************
; ********** show graph    
show_graph proc near
; ********** set the video card color table
    push es
    push di 
    push y
    mov ax, 0a000h
    mov es, ax
    mov di, 0
    mov cx, 20
    add y, 48
    mov al, 20
    mul show_y
    add y, ax
    cld

sget_data:
    dec y
    mov ax, 320
    mul y
    add ax, 10
    mov di, ax
    mov ax, 20
    mul show_x
    add di, ax

    push cx
    mov cx,20
    rep  movsb
    pop cx
    loop sget_data
    pop y
    pop di
    pop es
  
    ret 
show_graph endp

; ************************************************************************************************************************
; ************************************************************************************************************************
; ********** close file
close_file proc near
    mov bx, file_symbol
    mov ah, 3eh
    int 21h
    ret
close_file endp
 
       
; ************************************************************************************************************************
; ************************************************************************************************************************
; ********** dispose game end
dispose_game_end proc near 
; ********** show menu picture
    lea dx, gameend_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
    
; ********** get sound
    call sound

    call show_picture    ; read the picture data from the file and transport them to the video buffer
    call close_file    ; close the gameend file
    call show_string_end
    call read_key_end
    ret
dispose_game_end endp


; ************************************************************************************************************************
; ************************************************************************************************************************
; ********** show string 
show_string_end proc near
   push es
   mov al, 0
   lea bp, new_game_string
   mov cx, 11
   mov dh, 8
   mov dl, 14
   mov ah, 13h
   int 10h
   lea bp, finally_picture
   mov cx, 18
   add dh, 2
   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, 10
   add dh, 3
   mov dl, 9
   mov ah, 13h
   int 10h
  
   pop es
show_string_end endp


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

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

test_exit_end:
    cmp x, 65h         ; if e pressed the exit
    jnz  test_new_end

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

; ********** 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_end:
    cmp x, 6eh
    jnz test_grade_end

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

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

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

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

    call get_grade_picture_data
    call set_grade
    jmp read_end

; ********** if i pressed intro the game
test_intro_end:
    cmp x, 69h
    jnz test_finally_end
left_end:
; ********** input char
    mov ah, 0h
    int 16h
    cmp ah, 1ch
    jnz read_end

    call show_intro          
    jmp read_end

; ********** if f pressed intro the game
test_finally_end:
    cmp x, 66h
    jnz read_key_end_input_wrong
; ********** input char
    mov ah, 0h
    int 16h
    cmp ah, 1ch
    jnz read_end

    call show_finally_picture          
    jmp read_end

read_key_end_input_wrong:
; ********** show string : wrong input! 
    mov al, 0
    lea bp, input_wrong_string
    mov cx, 12
 

⌨️ 快捷键说明

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