赛马游戏界面
人机交互的游戏
马的素材在QQ群
规则
1、一个玩家,一个电脑,一个终点 ------界面设计
2、鼠标点击标签,控制玩家前进 ------点击一次,产生一个随机数前进
3、电脑随机前进 -------------通过随机数来获得前进距离,难度系数是指电脑随机数范围的大小
4、比较谁先到终点 -----------可以通过timer监控玩家与电脑谁先到达
界面属性配置与项目源代码:
VERSION 5.00 Begin VB.Form Form1 BackColor = &H00FFFFFF& Caption = "赛马游戏--刘金玉编程" ClientHeight = 6720 ClientLeft = 60 ClientTop = 405 ClientWidth = 11775 LinkTopic = "Form1" ScaleHeight = 6720 ScaleWidth = 11775 StartUpPosition = 3 'Windows Default Begin VB.CommandButton Command1 Caption = "开始游戏" Height = 735 Left = 3240 TabIndex = 6 Top = 5280 Width = 1455 End Begin VB.Timer Timer3 Enabled = 0 'False Interval = 1 Left = 10920 Top = 5040 End Begin VB.Timer Timer2 Enabled = 0 'False Interval = 100 Left = 240 Top = 4320 End Begin VB.Frame frameplayer Appearance = 0 'Flat BackColor = &H80000005& BorderStyle = 0 'None Caption = "Frame1" ForeColor = &H80000008& Height = 1575 Left = 0 TabIndex = 3 Top = 2760 Width = 1215 Begin VB.Label Label3 Alignment = 2 'Center BackStyle = 0 'Transparent Caption = "玩家" Height = 255 Left = 120 TabIndex = 4 Top = 0 Width = 855 End Begin VB.Image imgplayer Height = 900 Left = 0 Picture = "Form1.frx":0000 Stretch = -1 'True Top = 480 Width = 1320 End End Begin VB.Timer Timer1 Enabled = 0 'False Interval = 100 Left = 120 Top = 1680 End Begin VB.Frame framepc Appearance = 0 'Flat BackColor = &H80000005& BorderStyle = 0 'None Caption = "Frame1" ForeColor = &H80000008& Height = 1575 Left = 0 TabIndex = 1 Top = 240 Width = 1215 Begin VB.Image imgpc Height = 900 Left = 0 Picture = "Form1.frx":3557 Stretch = -1 'True Top = 360 Width = 1320 End Begin VB.Label Label2 Alignment = 2 'Center BackStyle = 0 'Transparent Caption = "电脑" Height = 255 Left = 120 TabIndex = 2 Top = 0 Width = 855 End End Begin VB.Line Line3 X1 = 10680 X2 = 10680 Y1 = 0 Y2 = 6720 End Begin VB.Label Label4 Alignment = 2 'Center Caption = "点我奔跑" BeginProperty Font Name = "微软雅黑" Size = 24 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 855 Left = 480 TabIndex = 5 Top = 5280 Width = 2295 End Begin VB.Label Label1 Alignment = 2 'Center BackColor = &H80000005& Caption = "终点区域" BeginProperty Font Name = "微软雅黑" Size = 42 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty ForeColor = &H80000008& Height = 4815 Left = 10680 TabIndex = 0 Top = 0 Width = 1095 End Begin VB.Line Line2 X1 = 0 X2 = 11760 Y1 = 4800 Y2 = 4800 End Begin VB.Line Line1 X1 = 0 X2 = 11760 Y1 = 2160 Y2 = 2160 End End Attribute VB_Name = "Form1" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Dim pcIndex% Dim playerIndex% Private Sub Command1_Click() Timer1.Enabled = True Timer2.Enabled = True Timer3.Enabled = True Command1.Enabled = False framepc.Left = 0 frameplayer.Left = 0 End Sub Private Sub Label4_Click() Randomize frameplayer.Left = frameplayer.Left + Rnd * 100 End Sub Private Sub Timer1_Timer() '制作PC马的动画 pcIndex = pcIndex + 1 If pcIndex > 6 Then pcIndex = 1 imgpc.Picture = LoadPicture(App.Path & "/imgs/h (" & pcIndex & ").jpg") Randomize framepc.Left = framepc.Left + Rnd * 100 End Sub Private Sub Timer2_Timer() '玩家的动画 playerIndex = playerIndex + 1 If playerIndex > 6 Then playerIndex = 1 imgplayer.Picture = LoadPicture(App.Path & "/imgs/h (" & playerIndex & ").jpg") End Sub Private Sub Timer3_Timer() If framepc.Left + framepc.Width >= Line3.X1 Then MsgBox "电脑获胜", vbInformation, "通知" Timer3.Enabled = False Command1.Enabled = True Exit Sub End If If frameplayer.Left + frameplayer.Width >= Line3.X1 Then MsgBox "玩家获胜", vbInformation, "通知" Timer3.Enabled = False Command1.Enabled = True Exit Sub End If End Sub
课堂总结
1、学会把复杂问题简单化,通过步骤分解的方式,分解成一个个简单的小问题
2、更加关注用户体验
3、游戏开发,必须注重游戏的可玩性,提高可玩性
图片素材: