游戏开发:经典赛马游戏回味【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、游戏开发,必须注重游戏的可玩性,提高可玩性

 

图片素材:

相关文章
|
4月前
|
存储 人工智能 数据安全/隐私保护
使用 Python 创造你自己的计算机游戏(游戏编程快速上手)第四版:第十章到第十四章
使用 Python 创造你自己的计算机游戏(游戏编程快速上手)第四版:第十章到第十四章
145 0
|
4月前
|
存储 人工智能 算法
使用 Python 创造你自己的计算机游戏(游戏编程快速上手)第四版:第十五章到第十八章
使用 Python 创造你自己的计算机游戏(游戏编程快速上手)第四版:第十五章到第十八章
131 1
|
4月前
|
存储 程序员 对象存储
使用 Python 创造你自己的计算机游戏(游戏编程快速上手)第四版:第十九章到第二十一章
使用 Python 创造你自己的计算机游戏(游戏编程快速上手)第四版:第十九章到第二十一章
77 0
|
10月前
|
存储 算法 C语言
C/C++趣味程序设计百例(1~10)
C/C++趣味程序设计百例(1~10)
|
10月前
|
算法 C++ 容器
C/C++趣味程序设计百例(71~80)
C/C++趣味程序设计百例(71~80)
374 0
|
10月前
|
算法 C语言 C++
C/C++趣味程序设计百例(11~20)
C/C++趣味程序设计百例(11~20)
110 0
|
10月前
|
算法 定位技术 C语言
C/C++趣味程序设计百例(51~60)
C/C++趣味程序设计百例(51~60)
|
12月前
游戏开发:碰撞模型,球球大作战小游戏【VB编程经典案例】
游戏开发:碰撞模型,球球大作战小游戏【VB编程经典案例】
|
12月前
游戏开发零基础入门教程(1):先对游戏有个概念
首先回答第一个问题,是的,学完这个教程后,你能够做出自己的游戏。这里,有一点儿地方需要澄清一下,“做出来”跟“能够做出来”是完全不同的,“做出来”是既定的事实,去做了,并且做出来了。而“能够做出来”只是一种想象,前提是要先“去做”。
206 0
|
12月前
|
搜索推荐
游戏开发中最常用的基础数学知识
我们也经常听到有人这样说:想学做游戏或者想学编程呀,你的数学得要好。数学学得好,逻辑思维才能好,才能把编程或者做游戏学好。这句话看上去好像是有道理,但是细琢磨一下,其中有不少的问题。想学好编程,严谨缜密的逻辑思维确实很重要,但是逻辑思维这个东西并不是天生的,是后天通过锻炼习得的,锻炼它的方式有很多,学数学或者学习编程都能够有效的锻炼一个人的逻辑思维能力。
108 0