当前位置: 源码素材网 » VB教程 » 详情页

一个VB游戏中的方块控制类

  •   时间:2020-02-11
  • 概述:游戏控制 方块控制

VB游戏编写中的方块类,可将数据从临时块读到当前块中,以规整化数据,这个过程只分析最小区域,注意,它需要规整的样式数据,方块的占位分析就教给方块槽对象来解决,在获得一个样式数据后,它会分析出一个读取的最小区域,这个过程会创建一个方块对象,获的块样式:

VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "block"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
'--这个是方块的类
Option Explicit
Private curblock As BlockStyle  '--始终保存的是当前块的矩阵数据
Private tmpBlock As BlockStyle '--临时块,以便旋转
Private rc As Long  '--行读取数
Private cc As Long  '--列读取数
Private cell As BallCell    '--单元彩球对象
Private styleindex As Long
'--至于方块的占位分析就教给方块槽对象来解决
'--在获得一个样式数据后,它会分析出一个读取的最小区域
'--这个过程会创建一个方块对象
'--获的块样式
Public Property Get StyleIdx() As Long
    StyleIdx = styleindex
End Property
Public Property Get MaxRow() As Long '==获取最大度曲区域
    MaxRow = rc
End Property
Public Property Get MaxCol() As Long
    MaxCol = cc
End Property
Public Property Set CellBall(newcell As BallCell) '--获取球对象
   Set cell = newcell
End Property
Public Property Get CellBall() As BallCell
    Set CellBall = cell
End Property
'--一个样式索引,一个球单元对象。
Public Sub CreateBlock(sidx As Integer, newcell As BallCell)
    '--由于创建有电脑来完成,这里不做检查
    '--第一步,从样式表中导入样式数据
    Set cell = newcell
    styleindex = sidx
    curblock = blockss(sidx)
    Scan
End Sub
'---翻转数据,为简化起见,只有右,就是顺时针的翻转
Public Sub RotateBlock()
    '--借助tmpblock来做数据空间,而后调用scan
    '--旋转数据,并整理
    Dim Row As Long, Col As Long
    Dim tr As Long, tc As Long
    tr = 0
    tc = 0
    For Col = 0 To 3
        For Row = 3 To 0
            tmpBlock.blockdata(tr, rc) = curblock.blockdata(Row, Col)
            tc = tc + 1
        Next
        tr = tr + 1
        tc = 0
    Next
    '--清除当前数据
    For Row = 0 To 3
        For Col = 0 To 3
            curblock.blockdata(Row, Col) = 0
        Next
    Next
    '--旋转完毕后,移动整理数据
    '--第一步,找到读取起点行,和列
    For Col = 0 To 3
        If tmpBlock.blockdata(0, Col) = 1 Then
            tr = 0
            tc = Col
            Exit For
        ElseIf tmpBlock.blockdata(1, Col) = 1 Then
            tr = 1
            tc = Col
            Exit For
        ElseIf tmpBlock.blockdata(2, Col) = 1 Then
            tr = 2
            tc = Col
            Exit For
        ElseIf tmpBlock.blockdata(3, Col) = 1 Then
            tr = 3
            tc = Col
            Exit For
        End If
    Next
    '--将数据从临时块读到当前块中,以规整化数据
    Dim tr1 As Long, tc1 As Long
    Dim wr As Long, wc As Long
    wr = 0
    wc = 0
    For tr1 = tr To 3
        For tc1 = tc To 3
            curblock.blockdata(wr, wc) = tmpBlock.blockdata(tr1, tc1)
            wc = wc + 1
        Next
        wr = wr + 1
        wc = 0
    Next
    '--调用扫描分析,求出最小区域
    Scan
End Sub
'--这个过程只分析最小区域,注意,它需要规整的样式数据
Private Sub Scan()
    Dim rmax As Long, cmax As Long
    Dim Row As Long, Col As Long
    rmax = 0
    cmax = 0
    For Row = 0 To 3
        For Col = 0 To 3
            If curblock.blockdata(Row, Col) = 1 Then
                If Col > cmax Then
                    cmax = Col
                End If
                If Row > rmax Then
                    rmax = Row
                End If
            End If
        Next
    Next
    rc = rmax   '--获取区域
    cc = cmax
End Sub

    相关声明:

      若“一个VB游戏中的方块控制类”有损您的权益,请告之我们删除内容。
      部分文章来源于网络,版权归原作者所有。