《骰子模拟程序设计》由会员分享,可在线阅读,更多相关《骰子模拟程序设计(7页珍藏版)》请在金锄头文库上搜索。
1、骰子模拟程序设计一、设计目标模拟实现骰子游戏。二、设计要求1. 通过按某键模拟投掷骰子。2. 模拟显示骰子的旋转,经过一段时间后骰子静止,根据静止时的数字大小确定输赢。3. 通过按某键可停止骰子旋转。4. 模拟投掷骰子的力度,通过按某键的时间长短或两次按键之间的时间间隔,控制骰子的旋转时间和转速。5. 通过按某键可正常退出模拟程序。三、设计提示本课题可用18分别代替骰子的八面数字,当按下某键的时候,数字开始滚动显示,当按下结束键时停止,屏幕上显示的就是当前数字。其中,按键检测、数字显示、时间长短均可以通过DOS、BIOS功能调用完成。STACK SEGMENT DW 64 DUP(?)STAC
2、K ENDSDATA SEGMENT MESSAGE DB NOTE:ENTER 1,2,3 TO CHOOSE SPEED,S TO STOP,E TO EXIT,$ RESULT DB YOUR NUMBER IS ,$ GO DB GOING!,$ STOP DB STOP!,$ TIME DB ?DATA ENDSCODE SEGMENT ASSUME DS:DATA,CS:CODEPOINT MACRO OP1,OP2 ;置光标位置 PUSH AX PUSH BX PUSH DX MOV AH,02H MOV BH,0 MOV DH,OP1 MOV DL,OP2 INT 10H PO
3、P DX POP BX POP AXENDMPRINT MACRO M ;输出字符 PUSH AX PUSH DX MOV DL,M MOV AH,02H INT 21H POP DX POP AXENDMSTART: MOV AX,DATA MOV DS,AX LEA SI,TIME MOV AH,01H MOV CX,3000H INT 10H MOV AX,0600H MOV BH,0CH XOR CX,CX MOV DX,1850H INT 10H POINT 7,18 LEA DX,MESSAGE MOV AH,09H INT 21H MOV AX,0600H MOV BH,0FCH
4、 MOV CX,0B26H MOV DX,0D2AH INT 10H POINT 12,20 LEA DX,RESULT MOV AH,09H INT 21H RESET: MOV AH,08 INT 21H CMP AL,1 JZ A0 CMP AL,2 JZ A0 CMP AL,3 JZ A0 CMP AL,E JZ EXIT JMP RESET A0: AND AH,00H MOV CL,0FFH MUL CL MOV CX,AX PUSH CX POINT 9,38 LEA DX,GO MOV AH,09H INT 21H POP CXA1: PUSH CX CALL RAND POP
5、 CX ADD BL,31H POINT 12,40 PRINT BL MOV AH,01H INT 16H CMP AL,S JZ CONTINUE LOOP A1CONTINUE: POINT 9,38 LEA DX,STOP MOV AH,09H INT 21H MOV AH,01H INT 16H CMP AL,1 JZ A1 CMP AL,2 JZ A1 CMP AL,3 JZ A1 CMP AL,E JZ EXIT JMP RESETRAND PROC PUSH CX PUSH DX PUSH AX CALL DELAY CALL DELAY MOV AH,00H INT 1AH MOV AX,DX AND AH,00H MOV DL,6 DIV DL MOV BL,AH POP AX POP DX POP CX RETRAND ENDPDELAY PROC PUSH CX PUSH DX MOV DX, DEC DX JNZ D11D11: MOV CX,0FFFFHD12: LOOP D12 POP DX pop CX RETDELAY ENDPEXIT: INT 20H AG: JMP AG CODE ENDS END START调试结果:按下一次“1”键后:再按下一次“1”键后: