
VB课程设计报告打字游戏.doc
8页1108320134 冒震宇 课程设计题目 打字游戏一. 功能:本程序为无声版打字练习:有四个窗体,其中一个为开始窗体frmstart,游戏界面frmplay,还有一个为弹出键盘的界面frmkeyboard,还有一个为察看成绩界面frmscore其中frmstart为启动窗体还有一个模块用来存放全局变量和一个控制字母生成的全局过程 ziti还有一个文本文件用来储存玩家的信息二.课程详细设计:1)程序开始显示“打字设置”窗口,在“你的姓名”文本框中输入姓名若未输入姓名就单击“开始练习”或“查看成绩”按钮,则在屏幕上出现一个消息框在”打字屏幕上随机产生并下落各种字符.若用户在字符落到屏幕底下之前,敲击了键盘上的相应的键,则该字符被“击中”,然后消失程序根据速度和难度的设置自动计分,分数实时显示在窗口的顶部计分标准如下:1、慢速+小写字母:打中一个1分2、慢速+大写字母:打中一个2分3、慢速+混合字符:打中一个3分 4、中速+小写字母:打中一个4分5、中速+大写字母:打中一个5分6、中速+混合字符:打中一个6分7、高速+小写字母:打中一个7分8、高速+大写字母:打中一个8分9、高速+混合字符:打中一个9分 所有字符包括大小写字母,数字和符号字符.2)当下落字符中有相同字符时,一次只能打掉一个.如果按了屏幕上没有的字符则扣1分,如果有字符落到屏幕底下则扣10分.3)为了增加游戏的趣味性,可增加背景音乐和打中时的打击声.在此不作要求。
4)时间一到则显示用户本次的得分并提示是否继续进行.打字过程中可以按Esc键则中止游戏,返回打字设置窗口.5)打字练习过程中,屏幕的顶部显示已用的时间和当前的分数,按F1功能键则弹出键盘布局窗口以供用户参考.6)单击”查看成绩”按钮,弹出“成绩”对话框,显示当前用户每次的练习时间和成绩.三、程序代码展示Frmstart:Option ExplicitDim strtime As String '得到输入时间文本框的时间Private Sub cmdExit_Click() '退出按钮Unload frmPlay: Unload frmStart: Unload frmScoreEnd SubPrivate Sub cmdScore_Click() '察看成绩按钮Dim int7 As IntegerOpen "score.txt" For Input As 3 Do While Not EOF(3) Input #3, str1, str2, str3 str4 = str1 + " " + str2 + " " + str3 If str1 = frmStart.txtName.Text Then '如果找到则添加到列表框中 frmScore.lstScore.AddItem str4 End If If frmStart.txtName.Text = "" Then '如果搜索内容为空则全部显示 frmScore.lstScore.AddItem str4 End If str1 = "" str2 = "" str3 = "" str4 = "" Loop If frmScore.lstScore.ListCount = 0 Then '如果为空即姓名不存在则显示提示框 int7 = MsgBox("没有您的成绩纪录", 48, "成绩查看") If int7 = 1 Then Unload frmScore End If Else frmScore.Show End IfClose 3End SubPrivate Sub Form_Load() frmStart.lblTime.Caption = NowtxtTime.Text = "1"optSpeed(0).Value = True: optZimu(0).Value = TruetxtName.Text = ""End Sub Private Sub cmdStart_Click() '开始按钮Dim m As IntegerIf frmStart.txtName.Text = "" Then m = MsgBox("请您输入您的姓名", 32, "错误") Exit SubEnd IffrmStart.Visible = FalsefrmPlay.ShowEnd SubPrivate Sub txtTime_Change() '输入游戏时间,默认一分钟Dim int3 As Single '用来在strtime 和inttime 中间转换的一个变量strtime = txtTime.Textint3 = CSng(strtime)inttime = int3 * 60End SubFrmplay:Option ExplicitDim intSecond As IntegerDim intMinute As IntegerPrivate X As Integer '控制爆炸图画的出现和消失Private intend As Integer '控制游戏的结束Private Sub Form_Deactivate()If intend >= inttime Then intend = 0: Timer2.Enabled = False '如果是时间到了以后退出,则往文本文件里面写文件 Open "score.txt" For Append As 1 Write #1, frmStart.txtName.Text, CStr(t), frmStart.lblTime.Caption Close 1 End IfEnd SubPrivate Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)Dim int4 As IntegerIf KeyCode = 27 Then '用户按了ESC int4 = MsgBox("真的要结束练习吗?", 36, "打字练习") If int4 = 6 Then Unload frmPlay: frmStart.Visible = True End IfEnd IfIf KeyCode = 112 Then '用户按了F1 frmKeyboard.Show 1End IfEnd SubPrivate Sub Form_Load()intSecond = 0: intMinute = 0: intend = 0: t = 0Timer2.Enabled = True: Image1.Visible = FalsefrmPlay.WindowState = 2Dim h As Integer, z As Integer '循环变量For z = 0 To 9 '标签控件赋初值 lblShow(z).BackColor = frmPlay.BackColor lblShow(z).ForeColor = RGB(Rnd * 255, Rnd * 255, Rnd * 255) lblShow(z).Top = frmPlay.Top - lblShow(z).HeightNext zFor h = 0 To 2 '根据速度的设定来控制下落的速度 If frmStart.optSpeed(h).Value = True Then Timer1.Interval = 50 * (3 - h) Call Ziti '随机生成字体 End IfNext hLabel1.BackColor = Frame1.BackColor: Label2.BackColor = Frame1.BackColor: Label3.BackColor = Frame1.BackColorFrame1.Width = frmPlay.Width + 1000End SubPrivate Sub Timer1_Timer() '搜索是否有字母到底RandomizeDim intx As IntegerFor intx = 0 To 9 If lblShow(intx).Top >= frmPlay.Height - lblShow(intx).Height Then t = t – 10 ‘有字母到底即扣去十分 If frmStart.optZimu(0).Value = True Then Randomize frmPlay.lblShow(intx).Caption = Chr(Rnd * 25 + 97) End If If frmStart.optZimu(1).Value = True Then Randomize frmPlay.lblShow(intx).Caption = Chr(Rnd * 47 + 65) If Asc(frmPlay.lblShow(intx).Caption) < 97 And Asc(frmPlay.lblShow(intx).Caption) > 90 Then frmPlay.lblShow(intx).Caption = Chr(Rnd * 47 + 65) End If End If If frmStart.optZimu(2).Value = True Then Randomize frmPlay.lblShow(intx).Caption = Chr(Rnd * 57 + 65) End If lblShow(intx).Top = frmPlay.Top - lblShow(intx).Height lblShow(intx).ForeColor = RGB(Rnd * 255, Rnd * 255, Rnd * 255) End If lblShow(intx).Top = lblShow(intx).Top + Rnd * 200Next intx Label3.Caption = "欢迎" & frmStart.txtName.Text & _"您现在的得分是 " & tEnd SubPrivate Sub Timer2_Timer() '控制游戏的结束 Dim int5 As IntegerIf intend >= inttime Then '若大于游戏时间,则退出 int5 = MsgBox("本次练习你的成绩是" & CStr(t) & "分" & Chr(13) & Chr(10) 。
