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

📄 game.txt

📁 用汇编编的一个游戏
💻 TXT
📖 第 1 页 / 共 2 页
字号:
;**********************************************
;*                  Made by Lin Jiang         *
;*  由于英语水平有限,注释只好用中文了,在DOS     *
;*         用EDIT的朋友就得麻烦麻烦了:)        *
;**********************************************        




;初始化程序界面的宏,共七个参数
;op1,op2:打印边框的初始位置 
;op3:要打印的字符的ASCII代码
;op4:循环自增方向
;op5:打印次数 op6:标号
;op7:字符的颜色
;参数实在太多了,考虑了很久,我觉得还是写成宏好些!

Init_game macro  op1,op2,op3,op4,op5,op6,op7                        
                                                                 
        mov cx,00h                                  
        mov dh,op1                                
        mov dl,op2
op6:                        
        mov ah,02h
        mov bh,00h                                                        
        int 10h
        
        push cx
        mov ah,09h
        mov al,op3
        mov bh,00h
        mov bl,op7
        mov cx,01h
        int 10h
        pop cx
        inc cx
        inc op4
        cmp cx,op5
        jne op6        
        endm

;清屏的宏, 四个参数,分别是左上角和右下角座标
;由于用得太多,也写成宏

clear_screen macro op1,op2,op3,op4                        
        mov ah,06h                                                  
        mov al,00h
        mov bh,07h
        mov ch,op1
        mov cl,op2
        mov dh,op3
        mov dl,op4
        int 10h
        mov ah,02h
        mov bh,00h
        mov dh,00h
        mov dl,00h
        int 10h
        endm
        
;显示菜单和信息提示的宏
;功能是先把光标置于要显示位置,然后用DOS的
;9号中断显示字符串

menu    macro  op1,op2,op3                                  
        mov ah,02h
        mov bh,00h
        mov dh,op1
        mov dl,op2
        int 10h
        mov ah,09h
        lea dx,op3
        int 21h
        endm

data segment        
                                                
;初始菜单内容

linjiang db "Made by lin jiang$"                                
meg db "Let us have a game!!Come on!!$"
meg1 db "**Select Menu**$"
meg2 db "Please select the game speed,ESC to quit.$"
meg3 db "1.Very slow      Too easy,speed up!$"
meg4 db "2.Slow           Everybody can deal.$"
meg5 db "3.Nomal          I think you can deal!$"
meg6 db "4.Fast           A challenge.Pay attention!$"
meg7 db "5.Very Fast      Too hard,Have a try?$"
meg8 db "6.Fastest    Are you crazy??$"
meg9 db "*Select the number among 1-6 and press ENTER to start!*$"
meg10 db "Game Speed Select:$"

;显示功能键内容
hotkey  db "When you are playing games:$"                
hotkey1 db "ESC to return to menu$"
hotkey2 db "SPACE to pause the game$"
hotkey3 db "Press any key to play games......$"
hotkey4 db "Are you ready??$"

;显示游戏失败后的信息
failmeg  db "The letter arrives the bottom, You are lost ! :($"                
failmeg0 db "Press ENTER to go on......$"
failmeg1 db "Game is over!$"
failmeg2 db "Press ENTER to return  menu and press ESC to exit!$"
failmeg3 db "Bye-Bye!Thank for your playing!!$"
failmeg4 db "Press any key to quit......$"


;时间延迟
speed dw 00d,1200d,700d,400d,350d,200d,20d                                


;字母数组 
                  
letters  db "jwmilzoeucgpravskntxhdyqfb"                
         db "iytpkwnxlsvxrmofzhgaebudjq"
         db "nwimzoexrphysfqtvdcgljukda"

;由于第二次运行游戏时内存中的内容已经改变,故重新初始化
;此处是一个备份,不会改变。

letters_bak db "jwmilzoeucgpravskntxhdyqfb"                
            db "iytpkwnxlsvxrmofzhgaebudjq"                
            db "nwimzoexrphysfqtvdcgljukda"

;一个对字母计数的计数器,当等于78的时候,清零。

letter_counter db 0                                        
life_flag db 78 dup(0)

;位置状态数组,1表示已经遍历过了
;字母位置当前值

position_flag db 78 dup(0)                                
present_position db 1                                        

data ends


stack segment para stack 'stack'
          db 64 dup(0)
stack ends


code segment
main proc far
assume cs:code,ds:data,ss:stack
start:
                  
        mov ax,data
        mov ds,ax

;选择视频模式        

        mov ah,03h
        int 10h

;使用调色板设置游戏背景色

        mov ax,1010h
        mov bx,0
        mov ch,0
        mov cl,16
        mov dh,0
        int 10h
;由于第二次运行游戏时这些变量已经改变,故重赋值

        mov letter_counter,00h                                         
        mov present_position,1                         

;opsition_flag数组清零
        lea si,position_flag                                

        mov ah,00h
        mov cx,00h

init_postion_flag:        
        mov [si],ah
        inc si
        inc cx
        cmp cx,78d
        jne init_postion_flag
        
;字母数组letters恢复原值
        lea di,letters                                         
        lea si,letters_bak
        mov cx,00h
init_letters:
        mov ah,[si]
        mov [di],ah
        inc si
        inc di
        inc cx
        cmp cx,78d
        jne init_letters


        mov ah,00h
        lea si,life_flag
        mov cx,00h
init_life_flag:
        mov [si],ah
        inc si
        inc cx
        cmp cx,78d
        jne init_life_flag


                                                        
;主程序部分


;关闭光标
        mov cx,00h                                        
        mov ah,01h                                        
        or  ch,00010000b
        int 10h
;清屏的宏展开
        clear_screen 00d,00d,24d,79d                        

        
;初始化游戏界面的宏展开(游戏边框)
Init_game 00d,00d,0ah,dl,80d,nextsign1,0011b                                 

Init_game 24d,00d,0ah,dl,80d,nextsign2,0011b

Init_game 00d,00d,0ah,dh,25d,nextsign3,0011b

Init_game 00d,79d,0ah,dh,25d,nextsign4,0011b



;菜单信息的宏展开
menu 01d,15d,meg                                        
menu 01h,61d,linjiang                                        
menu 03d,20d,meg1
menu 05d,15d,meg2
menu 07d,15d,meg3
menu 09d,15d,meg4
menu 11d,15d,meg5
menu 13d,15d,meg6
menu 15d,15d,meg7
menu 17d,15d,meg8
menu 19d,15d,meg9
menu 22d,15d,meg10

        

;处理菜单输入选择的代码段

input:  mov ah,02h                                        
        mov bh,00h
        mov dh,22d
        mov dl,33d
        int 10h

        mov ah,0ah
        mov al," "
        mov bh,00h
        mov cx,01h
        int 10h

        mov ah,01h
        int 21h

;六种备选的速度值

retry:  cmp al,"1"
        je speed1
        cmp al,"2"
        je speed2
        cmp al,"3"
        je speed3
        cmp al,"4"
        je speed4
        cmp al,"5"
        je speed5
        cmp al,"6"
        je speed6
        cmp al,1bh
        je to_over0
        jmp input

to_over0:jmp over        

         
speed1: mov ah,01h        ;速度1
        int 21h
        cmp al,0dh
        jne otherkey
        mov ax,speed+2
        mov speed,ax
        jmp begin 
          
speed2: mov ah,01h        ;速度2
        int 21h
        cmp al,0dh
        jne otherkey
        mov ax,speed+4
        mov speed,ax
        jmp begin

speed3: mov ah,01h        ;速度3
        int 21h
        cmp al,0dh
        jne otherkey
        mov ax,speed+6
        mov speed,ax
        jmp begin

speed4: mov ah,01h        ;速度4
        int 21h
        cmp al,0dh
        jne otherkey
        mov ax,speed+8
        mov speed,ax
        jmp begin

speed5: mov ah,01h        ;速度5
        int 21h
        cmp al,0dh
        jne otherkey
        mov ax,speed+10
        mov speed,ax
        jmp begin

speed6: mov ah,01h        ;速度6
        int 21h
        cmp al,0dh
        jne otherkey
        mov ax,speed+12
        mov speed,ax
        jmp begin        
        
;处理重复输入的代码段
otherkey:                                                

        push ax
        mov ah,02h
        mov bh,00h
        mov dh,22d
        mov dl,34d
        int 10h

        mov ah,0ah
        mov al," "
        mov bh,00h
        mov cx,01h
        int 10h

        mov ah,02h
        mov bh,00h
        mov dh,22d
        mov dl,33d
        int 10h
        pop ax

        mov dx,ax
        mov ah,02h
        int 21h

        jmp retry        
                                  
;输入结束        

begin:                                                  

        clear_screen 01d,01d,23d,78d

;显示热键相关信息

        menu 08d,20d,hotkey                                
        menu 10d,20d,hotkey1
        menu 12d,20d,hotkey2
        menu 14d,20d,hotkey4
        menu 16d,20d,hotkey3
        
        mov ah,07h
        int 21h

;清屏,开始游戏

        clear_screen 01d,01d,23d,78d                        
        Init_game 23d,01d,01h,dl,78d,nextsign5,1100b

;光标初始化

        mov ah,02h                                        
        mov bh,00h

⌨️ 快捷键说明

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