返回列表 回复 发帖

[分享]一个有趣的打字游戏

  1. ;--------------------------------------------------------------------------------
  2. ;此模板是纯DOS程序代码,需要MASM5.0,编译时请使用"编译 -> DOS"方式。
  3. ;--------------------------------------------------------------------------------
  4. Init_game macro op1,op2,op3,op4,op5,op6
  5. mov cx,00h
  6. mov dh,op1
  7. mov dl,op2
  8. op6:
  9. mov ah,02h
  10. mov bh,00h
  11. int 10h
  12. push cx
  13. mov ah,0ah
  14. mov al,op3
  15. mov bh,00h
  16. mov cx,01h
  17. int 10h
  18. pop cx
  19. inc cx
  20. inc op4
  21. cmp cx,op5
  22. jne op6
  23. endm
  24. clear_screen macro op1,op2,op3,op4
  25. mov ah,06h
  26. mov al,00h
  27. mov bh,07h
  28. mov ch,op1
  29. mov cl,op2
  30. mov dh,op3
  31. mov dl,op4
  32. int 10h
  33. mov ah,02h
  34. mov bh,00h
  35. mov dh,00h
  36. mov dl,00h
  37. int 10h
  38. endm
  39. menu macro op1,op2,op3
  40. mov ah,02h
  41. mov bh,00h
  42. mov dh,op1
  43. mov dl,op2
  44. int 10h
  45. mov ah,09h
  46. lea dx,op3
  47. int 21h
  48. endm
  49. data segment
  50. linjiang db "Made by lin jiang$"
  51. no db "NO.:021411$"
  52. meg db "Let us have a game!!Come on!!$"
  53. meg1 db "**Select Menu**$"
  54. meg2 db "Please select the game speed,ESC to quit.$"
  55. meg3 db "1.Very slow Too easy,speed up!$"
  56. meg4 db "2.Slow Everybody can deal.$"
  57. meg5 db "3.Nomal I think you can deal!$"
  58. meg6 db "4.Fast A challenge.Pay attention!$"
  59. meg7 db "5.Very Fast Too hard,Have a try?$"
  60. meg8 db "6.Fastest Are you crazy??$"
  61. meg9 db "*Select the number among 1-6 and press ENTER to start!*$"
  62. meg10 db "Game Speed Select:$"
  63. hotkey db "When you are playing games:$"
  64. hotkey1 db "ESC to return to menu$"
  65. hotkey2 db "SPACE to pause the game$"
  66. hotkey3 db "Press any key to play games......$"
  67. hotkey4 db "Are you ready??$"
  68. failmeg db "The letter is arrive the bottom, You are lost ! :($"
  69. failmeg0 db "Press ENTER to go on......$"
  70. failmeg1 db "Game is over!$"
  71. failmeg2 db "Press ENTER to return menu and press ESC to exit!$"
  72. failmeg3 db "Bye-Bye!Thank for your playing!!$"
  73. failmeg4 db "Press any key to quit......$"
  74. speed dw 00d,1200d,800d,600d,400d,200d,100d
  75. letters db "jwmilzoeucgpravskntxhdyqfb"
  76. db "iytpkwnxlsvxrmofzhgaebudjq"
  77. db "nwimzoexrphysfqtvdcgljukda"
  78. letters_bak db "jwmilzoeucgpravskntxhdyqfb"
  79. db "iytpkwnxlsvxrmofzhgaebudjq"
  80. db "nwimzoexrphysfqtvdcgljukda"
  81. letter_counter db 0
  82. life_flag db 78 dup(0)
  83. position_flag db 78 dup(0)
  84. present_position db 1
  85. data ends
  86. stack segment para stack 'stack'
  87. db 64 dup(0)
  88. stack ends
  89. code segment
  90. main proc far
  91. assume cs:code,ds:data,ss:stack
  92. start:
  93. mov ax,data
  94. mov ds,ax
  95. mov letter_counter,00h
  96. mov present_position,1
  97. lea si,position_flag
  98. mov ah,00h
  99. mov cx,00h
  100. init_postion_flag:
  101. mov [si],ah
  102. inc si
  103. inc cx
  104. cmp cx,78d
  105. jne init_postion_flag
  106. lea di,letters
  107. lea si,letters_bak
  108. mov cx,00h
  109. init_letters:
  110. mov ah,[si]
  111. mov [di],ah
  112. inc si
  113. inc di
  114. inc cx
  115. cmp cx,78d
  116. jne init_letters
  117. mov ah,00h
  118. lea si,life_flag
  119. mov cx,00h
  120. init_life_flag:
  121. mov [si],ah
  122. inc si
  123. inc cx
  124. cmp cx,78d
  125. jne init_life_flag
  126. mov cx,00h
  127. mov ah,01h
  128. or ch,00010000b
  129. int 10h
  130. clear_screen 00d,00d,24d,79d
  131. Init_game 00d,00d,0ah,dl,80d,nextsign1
  132. Init_game 24d,00d,0ah,dl,80d,nextsign2
  133. Init_game 00d,00d,0ah,dh,25d,nextsign3
  134. Init_game 00d,79d,0ah,dh,25d,nextsign4
  135. menu 01d,15d,meg ;菜单信息的宏展开
  136. menu 01h,61d,linjiang
  137. menu 03d,20d,meg1
  138. menu 03d,68d,no
  139. menu 05d,15d,meg2
  140. menu 07d,15d,meg3
  141. menu 09d,15d,meg4
  142. menu 11d,15d,meg5
  143. menu 13d,15d,meg6
  144. menu 15d,15d,meg7
  145. menu 17d,15d,meg8
  146. menu 19d,15d,meg9
  147. menu 22d,15d,meg10
  148. input: mov ah,02h
  149. mov bh,00h
  150. mov dh,22d
  151. mov dl,33d
  152. int 10h
  153. mov ah,0ah
  154. mov al," "
  155. mov bh,00h
  156. mov cx,01h
  157. int 10h
  158. mov ah,01h
  159. int 21h
  160. retry: cmp al,"1"
  161. je speed1
  162. cmp al,"2"
  163. je speed2
  164. cmp al,"3"
  165. je speed3
  166. cmp al,"4"
  167. je speed4
  168. cmp al,"5"
  169. je speed5
  170. cmp al,"6"
  171. je speed6
  172. cmp al,1bh
  173. je to_over0
  174. jmp input
  175. to_over0:jmp over
  176. speed1: mov ah,01h
  177. int 21h
  178. cmp al,0dh
  179. jne otherkey
  180. mov ax,speed+2
  181. mov speed,ax
  182. jmp begin
  183. speed2: mov ah,01h
  184. int 21h
  185. cmp al,0dh
  186. jne otherkey
  187. mov ax,speed+4
  188. mov speed,ax
  189. jmp begin
  190. speed3: mov ah,01h
  191. int 21h
  192. cmp al,0dh
  193. jne otherkey
  194. mov ax,speed+6
  195. mov speed,ax
  196. jmp begin
  197. speed4: mov ah,01h
  198. int 21h
  199. cmp al,0dh
  200. jne otherkey
  201. mov ax,speed+8
  202. mov speed,ax
  203. jmp begin
  204. speed5: mov ah,01h
  205. int 21h
  206. cmp al,0dh
  207. jne otherkey
  208. mov ax,speed+10
  209. mov speed,ax
  210. jmp begin
  211. speed6: mov ah,01h
  212. int 21h
  213. cmp al,0dh
  214. jne otherkey
  215. mov ax,speed+12
  216. mov speed,ax
  217. jmp begin
  218. otherkey: ; 处理重复输入的代码段
  219. push ax
  220. mov ah,02h
  221. mov bh,00h
  222. mov dh,22d
  223. mov dl,34d
  224. int 10h
  225. mov ah,0ah
  226. mov al," "
  227. mov bh,00h
  228. mov cx,01h
  229. int 10h
  230. mov ah,02h
  231. mov bh,00h
  232. mov dh,22d
  233. mov dl,33d
  234. int 10h
  235. pop ax
  236. mov dx,ax
  237. mov ah,02h
  238. int 21h
  239. jmp retry
  240. begin:
  241. clear_screen 01d,01d,23d,78d
  242. menu 08d,20d,hotkey
  243. menu 10d,20d,hotkey1
  244. menu 12d,20d,hotkey2
  245. menu 14d,20d,hotkey4
  246. menu 16d,20d,hotkey3
  247. mov ah,07h
  248. int 21h
  249. clear_screen 01d,01d,23d,78d
  250. Init_game 23d,01d,01h,dl,78d,nextsign5
  251. mov ah,02h ;光标初始化
  252. mov bh,00h
  253. mov dh,01h
  254. mov dl,01h
  255. int 10h
  256. mov cx,00h
  257. lea si,letters
  258. nextletter: ; 初始化屏幕上方的字母
  259. mov ah,02h
  260. mov dl,[si]
  261. int 21h
  262. inc si
  263. inc cx
  264. cmp cx,78d
  265. je nextcycle
  266. jmp nextletter
  267. from_front: ; 相关循环的算法
  268. sub present_position,78d
  269. jmp gobackto_si
  270. find_zero:cmp letter_counter,78d
  271. je recycle
  272. cmp present_position,78d
  273. je from_one
  274. mov ah,00h
  275. nextsi: add present_position,01h
  276. inc si
  277. cmp [si],ah
  278. je gobackto_di
  279. cmp present_position,78d
  280. je from_one
  281. jmp nextsi
  282. from_one:mov present_position,01h
  283. jmp gobackto_si
  284. recycle:mov letter_counter,00h
  285. mov present_position,01d
  286. lea si,position_flag
  287. mov cx,00h
  288. mov ah,00h
  289. clearsi: mov [si],ah
  290. inc cx
  291. cmp cx,78d
  292. je nextcycle
  293. inc si
  294. jmp clearsi
  295. nextcycle:
  296. lea di,letters
  297. lea si,position_flag
  298. add present_position,31d
  299. cmp present_position,78
  300. ja from_front
  301. gobackto_si:
  302. add si,word ptr present_position
  303. dec si
  304. mov ah,[si]
  305. cmp ah,01h
  306. je find_zero
  307. gobackto_di:
  308. mov ah,01h
  309. mov [si],ah
  310. add di,word ptr present_position
  311. dec di
  312. mov dl,present_position
  313. mov ah,02h ; 字母下落的代码段部分
  314. mov bh,00h
  315. mov dh,01h
  316. int 10h
  317. mov cx,00h
  318. nextrow:push cx ; 新的一行
  319. mov cx,00h
  320. out_cycle: ; 延迟
  321. push cx
  322. mov cx,00h
  323. in_cycle:
  324. add cx,01h
  325. cmp cx,50000d
  326. jne in_cycle
  327. push dx
  328. mov ah,06h
  329. mov dl,0ffh
  330. int 21h
  331. pop dx
  332. jz pass ; 如果键盘缓冲区部分为空,则跳转
  333. cmp al,1bh ; 如果键入ESC,则返回主菜单
  334. je to_start1
  335. cmp al," " ;如果键入SPACE,则游戏暂停
  336. je pause
  337. cmp al,[di] ;输入字母正确!跳转!
  338. je disappear
  339. pass:
  340. pop cx
  341. inc cx
  342. cmp cx,speed
  343. je print
  344. jmp out_cycle
  345. pause: push dx ;暂停处理
  346. mov ah,06h
  347. mov dl,0ffh
  348. int 21h
  349. pop dx
  350. cmp al," "
  351. jne pause
  352. jmp pass
  353. to_start1: ;返回主菜单
  354. jmp start
  355. print:
  356. mov ah,0ah
  357. mov al," "
  358. mov bh,00h
  359. mov cx,01h
  360. int 10h
  361. inc dh
  362. mov ah,02h
  363. mov bh,00h
  364. int 10h
  365. mov ah,0ah
  366. mov al,[di]
  367. mov bh,00h
  368. mov cx,01h
  369. int 10h
  370. pop cx
  371. inc cx
  372. cmp cx,21d
  373. je print_next_letter
  374. jmp nextrow ; 下一行
  375. disappear: ; 击中字母后的相关处理
  376. pop cx
  377. pop cx
  378. mov ah,0ah
  379. mov al," "
  380. mov bh,00h
  381. mov cx,01h
  382. int 10h
  383. jmp hit
  384. print_next_letter: ; 处理原位置的空缺
  385. lea si,life_flag
  386. add si,word ptr present_position
  387. dec si
  388. mov ah,[si]
  389. cmp ah,1
  390. je fail
  391. mov ah,0ah
  392. mov al," "
  393. mov bh,00h
  394. mov cx,01h
  395. int 10h
  396. inc dh
  397. mov ah,02h
  398. mov bh,00h
  399. int 10h
  400. mov ah,0ah
  401. mov al," "
  402. mov bh,00h
  403. mov cx,01h
  404. int 10h
  405. mov ah,1
  406. mov [si],ah
  407. hit: mov ah,02h
  408. mov bh,00h
  409. mov dh,01h
  410. mov dl,present_position
  411. int 10h
  412. mov al,[di] ; 出现下一个新字母的数法
  413. add al,7
  414. cmp al,7ah
  415. ja convey_letter
  416. mov ah,0ah
  417. mov bh,00h
  418. mov cx,01h
  419. int 10h
  420. mov [di],al
  421. add letter_counter,01h
  422. jmp nextcycle
  423. convey_letter:
  424. sub al,7ah
  425. add al,61h
  426. mov ah,0ah
  427. mov bh,00h
  428. mov cx,01h
  429. int 10h
  430. mov [di],al
  431. add letter_counter,01h
  432. jmp nextcycle
  433. fail: mov ah,0ah ;游戏失败后的相关处理
  434. mov al," "
  435. mov cx,01h
  436. int 10h
  437. inc dh
  438. mov ah,02h
  439. mov bh,00h
  440. int 10h
  441. mov ah,0ah
  442. mov al,[di]
  443. mov bh,00h
  444. mov cx,01h
  445. int 10h
  446. mov ah,02h
  447. mov bh,00h
  448. mov dh,12d
  449. mov dl,17d
  450. int 10h
  451. push dx
  452. mov ah,09h
  453. lea dx,failmeg
  454. int 21h
  455. pop dx
  456. add dh,2
  457. mov ah,02h
  458. mov bh,00h
  459. int 10h
  460. mov ah,09h
  461. lea dx,failmeg0
  462. int 21h
  463. re: mov ah,07h
  464. int 21h
  465. cmp al,0dh
  466. jne re
  467. clear_screen 01,01,23,78
  468. mov ah,02h
  469. mov bh,00h
  470. mov dh,11d
  471. mov dl,20d
  472. int 10h
  473. push dx
  474. mov ah,09h
  475. lea dx,failmeg1
  476. int 21h
  477. pop dx
  478. inc dh
  479. inc dh
  480. mov ah,02h
  481. mov bh,00h
  482. int 10h
  483. mov ah,09h
  484. lea dx,failmeg2
  485. int 21h
  486. notkey:
  487. mov ah,07h
  488. int 21h
  489. cmp al,0dh
  490. je to_start
  491. cmp al,1bh
  492. je over
  493. jmp notkey
  494. to_start:
  495. clear_screen 00,00,24,79
  496. jmp start
  497. over: clear_screen 01,01,23,78
  498. mov ah,02h
  499. mov bh,00h
  500. mov dh,11d
  501. mov dl,15h
  502. int 10h
  503. mov ah,09h
  504. lea dx,failmeg3
  505. int 21h
  506. mov ah,02h
  507. mov bh,00h
  508. mov dh,13d
  509. mov dl,15h
  510. int 10h
  511. mov ah,09h
  512. lea dx,failmeg4
  513. int 21h
  514. mov ah,07h
  515. int 21h
  516. mov ah,07h
  517. int 21h
  518. clear_screen 00,00,24,79
  519. mov ax,4c00h
  520. int 21h
  521. main endp
  522. code ends
  523. end start 
复制代码

                     我是一个呼吸着现在的空气而生活在过去的人
               这样的注定孤独,孤独的身处闹市却犹如置身于荒漠
                                     我已习惯了孤独,爱上孤独
                                 他让我看清了自我,还原了自我
                             让我再静静的沉思中得到快乐和满足
                                   再孤独的世界里我一遍又一遍
                                   不厌其烦的改写着自己的过去
                                             延伸到现在与未来
                                       然而那只是泡沫般的美梦
                                 产生的时刻又伴随着破灭的到来
                         在灰飞烟灭的瞬间我看到的是过程的美丽
                                      而不是结果的悲哀。。。
返回列表