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

📄 wordtype.asm

📁 80x86汇编打字游戏程序 微机原理课程设计
💻 ASM
字号:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;窗口初始化宏定义
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Init_w 	macro	w_op1,w_op2,w_op3,w_op4,w_op5,w_op6,w_op7
	mov	cx,00h
	mov	dh,w_op1
	mov	dl,w_op2
w_op6:
	mov	ah,02h
	mov	bh,00h
	int	10h
	push	cx
	mov	ah,09h
	mov	al,w_op3
	mov	bh,00h
	mov	bl,w_op7
	mov	cx,01h
	int	10h
	pop	cx
	inc	cx
	inc	w_op4
	cmp	cx,w_op5
	jne	w_op6
endm

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;菜单初始化宏定义
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
menu	macro	m_op1,m_op2,m_op3
	mov	ah,02h
	mov	bh,00h
	mov	dh,m_op1
	mov	dl,m_op2
	int	10h
	mov	ah,09h
	lea	dx,m_op3
	int	21h
endm
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

draw_text	macro	t_op1,t_op2,t_op3
	mov	ax,data
	mov	es,ax
	mov	bp,offset t_op3
	mov	dh,t_op1
	mov	dl,t_op2
	mov	ah,02h
	int	10h
	mov	cx,18
	mov	al,00h
	mov	bh,00h
	mov	bl,04h			;框架颜色
	mov	ah,13h
	int	10h
endm
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
time_ch	macro c_op1,c_op2
	lea	di,c_op1
	lea	si,c_op2
	cld
	mov	cx,8
	rep	movsb
endm
;;;;;;;;;;

show_time	macro	s_op1,s_op2,s_op3,s_op4

	MOV 	dh,s_op1
	mov	dl,s_op2
	MOV 	BP,OFFSET s_op3
      	MOV 	CX,s_op4
       	MOV 	BX,004EH
   	MOV 	AX,1301H
      	INT 	10H

endm

data	segment
wel1	db 'This is a simple asm word game!$'
wel2	db 'Edited by lupengsheng--whut.dq0604$'
wel3	db 'When a letter is dropping,please hit it!$'
wel4	db 'Press space to pause$'
wel5	db 'Press ESC to return back main interface$'
wel6	db 'Press letter E to exit!$'
wel7	db 'Enter your name and press enter to start this game!$'
wel8	db 'Your name here:$'
player	db 'Player:'
player_na	db	6 dup(' '),'$'
failure	db 0
letter_counter	db 0
letter_count	dw 0
score	db 'score : '
score_show	db '  $'
score_number	db 0
score_number1	db 30h
score_number2	db 30h
char_pt	db 'char_?'
speed  	dw 0afffh
letters	db "qpwoeirutylaksjdhfgzmxncbvpslwpdlemdkgw"
letters_bak	db "qpwoeirutylaksjdhfgzmxncbvpslwpdlemdkgw"
letters_counter	db 0
letters_count	dw 0
life_flag	db 39 dup(0)
present_position	db 1
start_str	db 'start: $'
start_time	db 8 dup(':')
now_time	db 8 dup(':')
end_str		db 'end: $'
end_time	db 8 dup(':')
t_time		db 8 dup(':')
word_str	db 'total word: $'
text_frame	db 0c9h,16 dup(0cdh),0bbh
text_frame1	db 0bah,16 dup(20h),0bah
text_frame2	db 0bah,16 dup(20h),0bah
text_frame3	db 0bah,16 dup(20h),0bah
text_frame4	db 0bah,16 dup(20h),0bah
text_frame5	db 0bah,16 dup(20h),0bah
text_frame6	db 0bah,16 dup(20h),0bah
text_frame7	db 0bah,16 dup(20h),0bah
text_frame8	db 0bah,16 dup(20h),0bah
text_frame9	db 0bah,16 dup(20h),0bah
text_frame10	db 0cch,16 dup(0cdh),0b9h
text_frame11	db 0bah,16 dup(20h),0bah
text_frame12	db 0bah,16 dup(20h),0bah
text_frame13	db 0bah,16 dup(20h),0bah
text_frame14	db 0bah,16 dup(20h),0bah
text_frame15	db 0c8h,16 dup(0cdh),0bch	
data	ends

stack	segment stack
	db	200 dup(?)
stack	ends

code	segment
main proc far
	assume	cs:code,ds:data,ss:stack
start:
	mov	ax,data
	mov	ds,ax
	mov	es,ax
	mov	ax,0003h
	int	10h
	mov ah,01h
	or  ch,00010000b
	int 10h
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;利用宏初始化窗口边框
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	Init_w	00d,00d,02d,dl,80d,win_x1,04h
	Init_w	24d,00d,02d,dl,80d,win_x2,04h
	Init_w	00d,00d,02d,dh,25d,win_y1,04h
	Init_w	00d,79d,02d,dh,25d,win_y2,04h


	menu	08h,14h,wel1
	menu	09h,14h,wel2
	menu	0ah,14h,wel3
	menu	0bh,14h,wel4
	menu	0ch,14h,wel5
	menu	0dh,14h,wel6
	menu	0fh,14h,wel7
	menu	10h,14h,wel8
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;输入玩家名字	
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
input_name:
	mov	cx,16
	lea	si,player_na
next_input:
	mov	ah,01h
	int	21h
	cmp	al,08h
	jz	erase_name
	cmp	al,0dh
	jz	begin_game
	cmp	al,45h
	jz	exit
	mov	[si],al
	inc	si
	loop	next_input
	jmp	begin_game

	
	mov	ah,1h
	int	21h
exit:
	mov	ah,4ch
	int	21h

erase_name:
	push	cx
	push	ax
	mov	ah,0ah
	mov	al,' '
	mov	bl,00h
	mov	bh,00h
	mov	cx,1
	int	10h
	pop	ax
	pop	cx
	jmp	next_input
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

begin_game:
	
	call	clear_screen
	call	get_time
	time_ch	start_time,t_time
	mov letter_counter,00h
	mov present_position,1

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
        	lea si,letters
           	lea di,letters_bak
           	mov cx,00h
init_letters:				;LETTERS赋值LETTERS BAK				
           	mov ah,[di]
           	mov [si],ah
           	inc si
           	inc di
           	inc cx
           	cmp cx,39
           	jne init_letters

  		mov ah,00h
           	lea si,life_flag
           	mov cx,00h
init_life_flag:				  ;LIFE_FLAG赋值0
           	mov [si],ah
           	inc si
           	inc cx
           	cmp cx,39
           	jne init_life_flag
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;初始化菜单
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

	mov	ah,0bh
	mov	bx,0100h
	int	10h

	;call	clear_screen
	draw_text	04h,38h,text_frame
	draw_text	05h,38h,text_frame1
	draw_text	06h,38h,text_frame2
	draw_text	07h,38h,text_frame3
	draw_text	08h,38h,text_frame4
	draw_text	09h,38h,text_frame5
	draw_text	0ah,38h,text_frame6
	draw_text	0bh,38h,text_frame7
	draw_text	0ch,38h,text_frame8
	draw_text	0dh,38h,text_frame9
	draw_text	0eh,38h,text_frame10
	draw_text	0fh,38h,text_frame11
	draw_text	10h,38h,text_frame12
	draw_text	11h,38h,text_frame13
	draw_text	12h,38h,text_frame14
	draw_text	13h,38h,text_frame15
	Init_w 02d,05d,0dbh,dl,40d,rect_x1,04h
	Init_w 21d,05d,0dbh,dl,40d,rect_x2,04h
	Init_w 02d,05d,0dbh,dh,20d,rect_y1,04h
	Init_w 02d,45d,0dbh,dh,20d,rect_y2,04h
	call	show_info
	Init_w 20d,06d,0eh,dl,39d,yinfu,0fh
	menu	06d,58d,start_str
	show_time	06d,64d,start_time,08
	menu	08d,58d,end_str
	menu	10d,58d,word_str
	
;;;;;;;;;;;;;;;;;;show time
	mov	ah,02h
	mov	bh,00h
	mov	dh,04d
	mov	dl,06d
	int	10h
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;初始化字母
	mov	ax,data
	mov	es,ax
	mov	bp,offset letters
	mov	dh,03d
	mov	dl,06d
	mov	ah,02h
	int	10h
	mov	cx,39
	mov	al,00h
	mov	bh,00h
	mov	bl,0fh			;框架颜色
	mov	ah,13h
	int	10h
	jmp	nextcycle
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

from_front:     
         	sub present_position,39d  
         	jmp backto_si
find_zero:
        	cmp present_position,39d
         	je from_one
         	mov ah,00h
nextsi: 
	add present_position,01h
         	inc si
         	cmp [si],ah
         	je backto_di
         	cmp present_position,39
         	je from_one
         	jmp nextsi
from_one:

	mov present_position,01h   
         	jmp backto_si


nextcycle:       
         	lea di,letters
         	lea si,life_flag
         	add present_position,16d
         	cmp present_position,39
         	ja from_front
backto_si:
         	add si,word ptr present_position
         	dec si
         	mov ah,[si]
         	cmp ah,01h
         	je find_zero
backto_di:
         	;mov ah,01h
         	;mov [si],ah
	push	cx
	xor	ch,ch
	mov	cl,present_position
inc_di:
	inc	di
	loop	inc_di
	pop	cx
         	;add di,word ptr present_position
	dec di	;		DI为字母位置指针,开始指向LETTERS首地址
         	mov dl,present_position
	add dl,05
         	mov ah,02h  
         	mov bh,00h          
         	mov dh,03h
         	int 10h				;找相对应都字母位置
         	mov cx,00h
nextrow: push cx  
         	mov cx,00h
out_cycle:              ; 延迟
         	push cx
         	mov cx,00h
in_cycle:
         	add cx,01h
         	cmp cx,1000
	    	jne in_cycle 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        	push dx
         	mov ah,06h     ;从键盘输入字符
         	mov dl,0ffh
         	int 21h
         	pop dx
         	jz pass         ;此行已经注释掉
         	cmp al,1bh     ;如果键入ESC,则返回主菜单
         	je to_start1
         	cmp al,' '     ;如果键入SPACE,则游戏暂停
         	je pause
         	cmp al,[di]    ;输入字母正确!则字母消失
         	je disappear
pass:    	pop cx
         	inc cx
         	cmp cx,speed
         	je print
         	jmp out_cycle
pause:   	push dx        ;暂停处理
         	mov ah,06h
         	mov dl,0ffh
         	int 21h
         	pop dx
         	cmp al,' '
         	jne pause
         	jmp pass

to_start1:              ;返回主菜单
        	jmp game_lose
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,09h      ;在当前光标位置写字母     
        	mov al,[di]
	mov bh,00h
	mov bl,0fh
        	mov cx,01h
        	int 10h
        	pop cx
        	inc cx
        	cmp cx,17d
        	je print_next_letter
        	jmp nextrow     ;下一行
disappear:              ;击中字母后输出空格
        	pop cx
        	pop cx
        	mov ah,0ah
        	mov al,' '
        	mov bh,00h
        	mov cx,01h
       		int 10h
		add	score_number,1d
		add	score_number1,1d
		push	ax
		push	si
		push	dx
		mov	al,score_number1
		lea	si,score_show
		cmp	al,'9'
		ja	score_next
		inc	si	
		mov	[si],al
		jmp	score_over
score_next:
		inc	score_number2
		mov	al,score_number2
		mov	[si],al
		mov	al,30h
		mov	score_number1,al
		inc	si
		mov	[si],al
	
score_over:	
		pop	si
		pop	ax
		call	show_info
     
		jmp hit  
print_next_letter:
		add	failure,1
		cmp	failure,39
		jz	game_lose
        	lea 	si,life_flag 			;击中下面的符号,符号消失
        	add si,word ptr present_position
        	dec si
        	mov ah,1
        	mov [si],ah
        	mov ah,0ah
        	mov al,20H
        	mov bh,00h
        	mov cx,01h
        	int 10h
        	inc dh      

hit: 		
		mov ah,02h				;上面字母消失
        	mov bh,00h
        	mov dh,03h
        	int 10h
        	mov al,[di]  ; 出现下一个新字母数值都算法
        	add al,7d
        	cmp al,'z'
        	ja convey_letter				;ja变jg
        	mov ah,0ah
        	mov bh,00h
        	mov cx,01h
        	int 10h
        	mov [di],al
		add	letters_counter,1
		push	dx
		push	ax
		push	bx
		push	cx
		call	show_counter
		pop	cx
		pop	bx
		pop	ax
		pop	dx
		show_time	12d,63d,letters_count,02
        	jmp nextcycle
game_lose:
		call	get_time
		time_ch	end_time,t_time
		menu	08d,58d,end_str
		show_time	08d,64d,end_time,08
game_again:
		mov	ah,06h
		mov	dl,0ffh
		int	21h
		jz	game_again
		jmp	start

convey_letter:   
        	sub al,'z'
        	add al,'a'
        	mov ah,0ah
        	mov bh,00h
        	mov cx,01h
        	int 10h
        	mov [di],al
		add	letters_counter,1
		push	dx
		push	ax
		push	bx
		push	cx
		call	show_counter
		pop	cx
		pop	bx
		pop	ax
		pop	dx
		show_time	12d,63d,letters_count,02
        	jmp nextcycle 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
show_counter	proc	near
		push	ax
		push	bx
		push	si
		mov	al,letters_counter
		cbw
		mov	bl,10
		div	bl
	;al放商,ah放余数
		add	al,'0'
		add	ah,'0'
		lea	si,letters_count
		mov	[si],al
		inc	si
		mov	[si],ah
		pop	si
		pop	bx
		pop	ax
		ret
show_counter	endp

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
show_info	proc	near
	push	ax
	push	bx
	push	cx
	push	dx
	mov	ah,02h
	mov	dh,16d
	mov	dl,58d
	int	10h
	lea	dx,player
	mov	ah,09h
	int	21h
	inc	dh
	mov	dh,17d
	mov	dl,58d
	mov	ah,02h
	int	10h
	lea	dx,score
	mov	ah,09h
	int	21h
	pop	dx
	pop	cx
	pop	bx
	pop	ax
	ret
show_info	endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;获取系统时间
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
get_time		proc	near
	MOV SI,0
      	MOV AH,2CH 
      	INT 21H
  	MOV AL,CH
     	call bcd2asc_t
      	INC SI
     	MOV AL,CL
     	call bcd2asc_t
      	INC SI
     	MOV AL,DH
      	call bcd2asc_t
      	INT 10H
	ret
get_time	endp

bcd2asc_t proc near              ;时间数值转换成ASCII码字符子程序
       PUSH BX
       CBW
       MOV BL,10
       DIV BL
       ADD AL,'0'
       MOV t_time[SI],AL
       INC SI
       ADD AH,'0'
       MOV t_time[SI],AH
       INC SI
       POP BX
       ret
bcd2asc_t endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
clear_screen	proc near
	mov	cx,0
	mov	dh,24h
	mov	dl,79h
	mov	bh,00h
	mov	ax,600h
	int	10h
	ret
clear_screen	endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	main	endp
	code	ends
end	start
	

⌨️ 快捷键说明

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