An interesting typing game for compiling source code

Source: Internet
Author: User
;--------------------------------------------------------------------------------
This template is pure DOS program code, need to MASM5.0, compile time use "compile-> DOS" way.
;--------------------------------------------------------------------------------
INIT_GAME Macro OP1,OP2,OP3,OP4,OP5,OP6
MOV cx,00h
MOV Dh,op1
MOV dl,op2
OP6:
MOV ah,02h
MOV bh,00h
int 10h
Push CX
MOV ah,0ah
MOV al,op3
MOV bh,00h
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
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$"
No db "no.:0 21411$ "
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 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 "Spaces to pause the game$"
Hotkey3 db "Press any key to play games......$"
Hotkey4 db "Are you ready??" $"
Failmeg db "The letter is arrive the bottom, your are lost!:( $"
FAILMEG0 db "Press ENTER to go on......$"
FAILMEG1 db "Game is over!$"
FAILMEG2 db "Press ENTER to return menu" and "pressing ESC to exit!$"
FAILMEG3 db "bye-bye! Thank for your playing!! $"
FAILMEG4 db "Press any key to quit......$"
Speed DW 00d,1200d,800d,600d,400d,200d,100d
Letters DB "JWMILZOEUCGPRAVSKNTXHDYQFB"
DB "IYTPKWNXLSVXRMOFZHGAEBUDJQ"
DB "Nwimzoexrphysfqtvdcgljukda"
Letters_bak db "JWMILZOEUCGPRAVSKNTXHDYQFB"
DB "IYTPKWNXLSVXRMOFZHGAEBUDJQ"
DB "Nwimzoexrphysfqtvdcgljukda"
Letter_counter DB 0
Life_flag db DUP (0)
Position_flag db DUP (0)
Present_position DB 1
Data ends
Stack segment para stack ' stack '
DB DUP (0)
Stack ends
Code segment
Main proc Far
Assume Cs:code,ds:data,ss:stack
Start
MOV Ax,data
MOV Ds,ax
MOV letter_counter,00h
MOV present_position,1
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
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
Init_game 24d,00d,0ah,dl,80d,nextsign2
Init_game 00d,00d,0ah,dh,25d,nextsign3
Init_game 00D,79D,0AH,DH,25D,NEXTSIGN4
Menu 01D,15D,MEG Macro Expansion
Menu 01h,61d,linjiang
Menu 03D,20D,MEG1
Menu 03d,68d,no
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
int 21h
CMP AL,0DH
Jne OtherKey
MOV ax,speed+2
MOV Speed,ax
JMP begin
Speed2:mov ah,01h
int 21h
CMP AL,0DH
Jne OtherKey
MOV ax,speed+4
MOV Speed,ax
JMP begin
Speed3:mov ah,01h
int 21h
CMP AL,0DH
Jne OtherKey
MOV ax,speed+6
MOV Speed,ax
JMP begin
Speed4:mov ah,01h
int 21h
CMP AL,0DH
Jne OtherKey
MOV ax,speed+8
MOV Speed,ax
JMP begin
Speed5:mov ah,01h
int 21h
CMP AL,0DH
Jne OtherKey
MOV ax,speed+10
MOV Speed,ax
JMP begin
Speed6:mov ah,01h
int 21h
CMP AL,0DH
Jne OtherKey
MOV ax,speed+12
MOV Speed,ax
JMP begin
OtherKey:; Code snippets that handle duplicate input
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
MOV ah,02h; cursor initialization
MOV bh,00h
MOV dh,01h
MOV dl,01h
int 10h
MOV cx,00h
Lea Si,letters
NextLetter:; Initialize the letters above the screen
MOV ah,02h
MOV Dl,[si]
int 21h
Inc si
Inc CX
CMP cx,78d
Je nextcycle
JMP NextLetter
From_front:; Algorithms for Correlation loops
Sub present_position,78d
JMP Gobackto_si
FIND_ZERO:CMP letter_counter,78d
JE Recycle
CMP present_position,78d
Je from_one
MOV ah,00h
Nextsi:add present_position,01h
Inc si
CMP [Si],ah
Je gobackto_di
CMP present_position,78d
Je from_one
JMP Nextsi
From_one:mov present_position,01h
JMP Gobackto_si
Recycle:mov letter_counter,00h
MOV present_position,01d
Lea Si,position_flag
MOV cx,00h
MOV ah,00h
Clearsi:mov [Si],ah
Inc CX
CMP cx,78d
Je nextcycle
Inc si
JMP Clearsi
Nextcycle:
Lea Di,letters
Lea Si,position_flag
Add present_position,31d
CMP present_position,78
JA from_front
Gobackto_si:
Add Si,word ptr present_position
Dec si
MOV Ah,[si]
CMP ah,01h
Je find_zero
Gobackto_di:
MOV ah,01h
mov [Si],ah
Add Di,word ptr present_position
Dec di
MOV dl,present_position
MOV ah,02h; Part of the code segment where the letters fall
MOV bh,00h
MOV dh,01h
int 10h
MOV cx,00h
Nextrow:push CX; A new line
MOV cx,00h
Out_cycle:; Delay
Push CX
MOV cx,00h
In_cycle:
Add cx,01h
CMP cx,50000d
Jne in_cycle
Push DX
MOV ah,06h
MOV DL,0FFH
int 21h
Pop DX
JZ Pass; If the keyboard buffer portion is empty, the jump
CMP al,1bh; If you type ESC, return to the main menu
Je to_start1
CMP al, ""; If you type space, the game is paused
Je Pause
CMP Al,[di]; Enter the letter correctly! Jump!
JE disappear
Pass
Pop CX
Inc CX
CMP Cx,speed
JE Print
JMP out_cycle
Pause:push dx; Pause processing
MOV ah,06h
MOV DL,0FFH
int 21h
Pop DX
CMP al, ""
Jne Pause
JMP Pass
To_start1:; Return to main Menu
JMP start
Print
MOV ah,0ah
mov al, ""
MOV bh,00h
MOV cx,01h
int 10h
Inc DH
MOV ah,02h
MOV bh,00h
int 10h
MOV ah,0ah
MOV Al,[di]
MOV bh,00h
MOV cx,01h
int 10h
Pop CX
Inc CX
CMP cx,21d
Je print_next_letter
JMP NextRow; Next line
Disappear:; Related processing after hitting the letter
Pop CX
Pop CX
MOV ah,0ah
mov al, ""
MOV bh,00h
MOV cx,01h
int 10h
JMP hit
Print_next_letter:; Handling vacancies in the original location
Lea Si,life_flag
Add Si,word ptr present_position
Dec si
MOV Ah,[si]
CMP ah,1
Je fail
MOV ah,0ah
mov al, ""
MOV bh,00h
MOV cx,01h
int 10h
Inc DH
MOV ah,02h
MOV bh,00h
int 10h
MOV ah,0ah
mov al, ""
MOV bh,00h
MOV cx,01h
int 10h
MOV ah,1
mov [Si],ah
Hit:mov ah,02h
MOV bh,00h
MOV dh,01h
MOV dl,present_position
int 10h
mov Al,[di]; The number method of the next new letter appears
Add al,7
CMP Al,7ah
JA convey_letter
MOV ah,0ah
MOV bh,00h
MOV cx,01h
int 10h
mov [di],al
Add letter_counter,01h
JMP nextcycle
Convey_letter:
Sub Al,7ah
Add al,61h
MOV ah,0ah
MOV bh,00h
MOV cx,01h
int 10h
mov [di],al
Add letter_counter,01h
JMP nextcycle
Fail:mov ah,0ah; related processing after a game failure
mov al, ""
MOV cx,01h
int 10h
Inc DH
MOV ah,02h
MOV bh,00h
int 10h
MOV ah,0ah
MOV Al,[di]
MOV bh,00h
MOV cx,01h
int 10h
MOV ah,02h
MOV bh,00h
MOV dh,12d
MOV dl,17d
int 10h
Push DX
MOV ah,09h
Lea Dx,failmeg
int 21h
Pop DX
Add dh,2
MOV ah,02h
MOV bh,00h
int 10h
MOV ah,09h
Lea Dx,failmeg0
int 21h
Re:mov ah,07h
int 21h
CMP AL,0DH
Jne RE
Clear_screen 01,01,23,78
MOV ah,02h
MOV bh,00h
MOV dh,11d
MOV dl,20d
int 10h
Push DX
MOV ah,09h
Lea DX,FAILMEG1
int 21h
Pop DX
Inc DH
Inc DH
MOV ah,02h
MOV bh,00h
int 10h
MOV ah,09h
Lea DX,FAILMEG2
int 21h
Notkey:
MOV ah,07h
int 21h
CMP AL,0DH
Je to_start
CMP AL,1BH
Je over
JMP Notkey
To_start:
Clear_screen 00,00,24,79
JMP start
Over:clear_screen 01,01,23,78
MOV ah,02h
MOV bh,00h
MOV dh,11d
MOV dl,15h
int 10h
MOV ah,09h
Lea Dx,failmeg3
int 21h
MOV ah,02h
MOV bh,00h
MOV dh,13d
MOV dl,15h
int 10h
MOV ah,09h
Lea DX,FAILMEG4
int 21h
MOV ah,07h
int 21h
MOV ah,07h
int 21h
Clear_screen 00,00,24,79
MOV ax,4c00h
int 21h
Main ENDP
Code ends
End Start

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.