当前位置:文档之家› 打字游戏

打字游戏

湖南农业大学东方科技学院课程设计报告课程名称:微机原理与接口技术设计题目:打字游戏程序设计学生姓名:罗英杰学号: 2年级专业:2008级计算机科学与技术班级: 3 班指导老师:王兴波学院:东方科技学院湖南·长沙提交日期:2009年12月一、任务与要求1. 开始界面的提示信息:进入游戏,退出2. 打字游戏:字母从屏幕上方下落,若用户在字母下落过程中输入正确字母,字母消失,输入不正确,字母继续下落3. 空格键退出游戏二、分析与规划1、结构分析图,如下2、布局分析:首先,出现菜单主界面起到提示作用。

然后进入游戏,接着完成游戏的退出。

三、实现过程1、出现菜单主界面:ZK db "WELCOME TO PLAY$"no db "shejiren: Luo Yingjie 2009/12/09 $"meg db "press Enter key to continue.......$"meg1 db "when a letter is dropping,please hit it!$"meg2 db "press space key to pause!$"meg3 db "press ESC key to return main interface!$"meg4 db "press letter 'E' to exit!$"上面的代码菜单主界面的内容clear_screen 00d,00d,24d,79dInit_game 00d,00d,0ah,dl,80d,nextsign1 Init_game 24d,00d,0ah,dl,80d,nextsign2Init_game 00d,00d,0ah,dh,25d,nextsign3Init_game 00d,79d,0ah,dh,25d,nextsign4menu 05d,15d,ZK ;菜单信息的宏调用menu 07h,15d,nomenu 09d,15d,megmenu 11d,15d,meg1menu 13d,15d,meg2menu 15d,15d,meg3menu 17d,15d,meg4clear_screen 01d,01d,23d,78d ;清屏宏调用clear_screen 01d,01d,23d,78dInit_game 23d,01d,01h,dl,78d,nextsign5mov ah,02hmov bh,00hmov dh,01hmov dl,01hint 10hmov cx,00hlea si,letterscmp al,1bh ;如果键入ESC,则返回主菜单to_start1: ;返回主菜单jmp start上面代码是解决怎样使主界面输出的2、游戏界面的实现:speed dw 600dletters db "jwmilzoeucgpravskntxhdyqfb"db "iytpkwnxlsvxrmofzhgaebudjq"db "nwimzoexrphysfqtvdcgljukda"letters_bak db "jwmilzoeucgpravskntxhdyqfb" db "iytpkwnxlsvxrmofzhgaebudjq" db "nwimzoexrphysfqtvdcgljukda" letter_counter db 0life_flag db 78 dup(0)position_flag db 78 dup(0)present_position db 1以上代码是字母的排列及出现的顺序init_postion_flag:mov [si],ahinc siinc cxcmp cx,78djne init_postion_flaglea di,letterslea si,letters_bakmov cx,00hinit_letters:mov ah,[si]mov [di],ahinc siinc diinc cxcmp cx,78djne init_lettersmov ah,00hlea si,life_flagmov cx,00hinit_life_flag:mov [si],ahinc siinc cxcmp cx,78djne init_life_flagmov cx,00hmov ah,01hor ch,00010000bint 10hput: mov ah,02h ;设置光标位置mov bh,00hmov dh,22dmov dl,33dint 10hmov ah,01h ;从键盘输入任意字符 int 21hcmp al,0dhje speed3cmp al,45hje exitexit: mov ah,4chint 21hspeed3: mov ax,speed+12mov speed,axjmp beginnextletter:mov ah,02h ;显示字母 mov dl,[si]int 21hinc siinc cxcmp cx,78dje nextcyclejmp nextletterfrom_front:sub present_position,78djmp gobackto_sifind_zero:cmp letter_counter,78dje recyclecmp present_position,78dje from_onemov ah,00hnextsi: add present_position,01hinc sicmp [si],ahje gobackto_dicmp present_position,78dje from_onejmp nextsifrom_one:mov present_position,01hjmp gobackto_sirecycle:mov letter_counter,00hmov present_position,01dlea si,position_flagmov cx,00hmov ah,00hclearsi: mov [si],ahinc cxcmp cx,78dje nextcycleinc sijmp clearsinextcycle:lea di,letterslea si,position_flagadd present_position,31dcmp present_position,78ja from_frontgobackto_si:add si,word ptr present_position dec simov ah,[si]cmp ah,01hje find_zerogobackto_di:mov ah,01hmov [si],ahadd di,word ptr present_positiondec dimov dl,present_positionmov ah,02hmov bh,00hmov dh,01hint 10hmov cx,00hnextrow: push cxmov cx,00hout_cycle: ; 延迟push cxmov cx,00hin_cycle:add cx,01hcmp cx,1000jne in_cyclepush dxmov ah,06h ;从键盘输入字符mov dl,0ffhint 21hpop dxjz passcmp al,[di] ;输入字母正确!则字母消失 je disappearpass: pop cxinc cxcmp cx,speedje printjmp out_cyclepause: push dx ;暂停处理mov ah,06hmov dl,0ffhint 21hpop dxcmp al," "jne pausejmp passto_start1: ;返回主菜单jmp startprint:mov ah,0ah ;在当前光标位置写空格 mov al," "mov bh,00hmov cx,01hint 10hinc dhmov ah,02h ;改变光标位置mov bh,00hint 10hmov ah,0ah ;在当前光标位置写字母 mov al,[di]mov bh,00hmov cx,01hint 10hpop cxinc cxcmp cx,21dje print_next_letterjmp nextrow ;下一行disappear: ;击中字母后输出空格 pop cxpop cxmov ah,0ahmov al," "mov bh,00hmov cx,01hint 10hjmp hitprint_next_letter:lea si,life_flagadd si,word ptr present_position dec simov ah,0ahmov al," "mov bh,00hmov cx,01hint 10hinc dhmov ah,02hmov bh,00hint 10hmov ah,0ahmov al," "mov bh,00hmov cx,01hint 10hmov ah,1mov [si],ahmov bh,00hmov dh,01hmov dl,present_positionint 10hmov al,[di] ; 出现下一个新字母的数法 add al,7cmp al,7ahja convey_lettermov ah,0ahmov bh,00hmov cx,01hint 10hmov [di],aladd letter_counter,01hjmp nextcycleconvey_letter:sub al,7ahadd al,61hmov ah,0ahmov bh,00hmov cx,01hint 10hmov [di],aladd letter_counter,01hjmp nextcycleclear_screen 01,01,23,78mov ah,02hmov bh,00hmov dh,11dint 10hinc dhinc dhmov ah,02hmov bh,00hint 10hnotkey:mov ah,07hint 21hcmp al,0dhje to_startcmp al,1bhje overjmp notkeyto_start:clear_screen 00,00,24,79jmp startover: clear_screen 01,01,23,78 mov ah,02hmov bh,00hmov dh,11dmov dl,15hint 10hmov ah,02hmov bh,00hmov dh,13dmov dl,15hint 10hmov ah,07hint 21hmov ah,07hint 21hclear_screen 00,00,24,79 mov ax,4c00hint 21h以上代码是实现游戏的所有代码四、实现的效果1、主界面实现的效果:2、游戏实现的效果:五、结束语在这次课程设计中,通过做打字游戏程序的设计,熟练掌握了编写汇编语言源程序的基本方法和框架;并能熟练编写顺序结果、分支结构和循环结构的汇编程序,而且还掌握了子程序的编写和使用的方法。

相关主题