游戏开发:经典赛马游戏回味【VB编程经典】

简介: 游戏开发:经典赛马游戏回味【VB编程经典】

赛马游戏界面



人机交互的游戏

马的素材在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、游戏开发,必须注重游戏的可玩性,提高可玩性

 

图片素材:

相关文章
|
5月前
|
存储 Ubuntu Shell
使用 Python 创造你自己的计算机游戏(游戏编程快速上手)第四版:致谢到第四章
使用 Python 创造你自己的计算机游戏(游戏编程快速上手)第四版:致谢到第四章
111 0
|
5月前
|
存储 人工智能 算法
使用 Python 创造你自己的计算机游戏(游戏编程快速上手)第四版:第十五章到第十八章
使用 Python 创造你自己的计算机游戏(游戏编程快速上手)第四版:第十五章到第十八章
146 1
|
5月前
|
存储 程序员 对象存储
使用 Python 创造你自己的计算机游戏(游戏编程快速上手)第四版:第十九章到第二十一章
使用 Python 创造你自己的计算机游戏(游戏编程快速上手)第四版:第十九章到第二十一章
111 0
|
5月前
|
存储 人工智能 数据安全/隐私保护
使用 Python 创造你自己的计算机游戏(游戏编程快速上手)第四版:第十章到第十四章
使用 Python 创造你自己的计算机游戏(游戏编程快速上手)第四版:第十章到第十四章
157 0
|
5月前
|
存储 Shell Go
使用 Python 创造你自己的计算机游戏(游戏编程快速上手)第四版:第五章到第九章
使用 Python 创造你自己的计算机游戏(游戏编程快速上手)第四版:第五章到第九章
136 0
游戏开发:碰撞模型,球球大作战小游戏【VB编程经典案例】
游戏开发:碰撞模型,球球大作战小游戏【VB编程经典案例】
120 0
游戏开发零基础入门教程(1):先对游戏有个概念
首先回答第一个问题,是的,学完这个教程后,你能够做出自己的游戏。这里,有一点儿地方需要澄清一下,“做出来”跟“能够做出来”是完全不同的,“做出来”是既定的事实,去做了,并且做出来了。而“能够做出来”只是一种想象,前提是要先“去做”。
245 0
零基础VB教程031期:碰撞模型-案例球球大作战游戏
零基础VB教程031期:碰撞模型-案例球球大作战游戏
|
监控 Windows
VB游戏开发#001植物大战僵尸小游戏开发思路说明及源码
VB游戏开发#001植物大战僵尸小游戏开发思路说明及源码
381 0
|
程序员
关于经典游戏俄罗斯方块,你不知道的那些事儿
大家好,我是小蚂蚁。今天带大家来了解一下那个已被载入游戏史册的伟大的游戏——俄罗斯方块。 为什么它被叫做是“俄罗斯方块”呢?因为它诞生于俄罗斯,并且游戏界面都是方块.....开个玩笑,这样的解释也太牵强了。不过,这个游戏诞生于俄罗斯确实是真的。
134 0