7,763
社区成员
发帖
与我相关
我的任务
分享
'方块矩阵翻转
Sub ChangeSqr()
Dim x As Integer, y As Integer
Dim Sqr(3, 3) As Boolean
y = 0
While y <= 2
x = 0
While x <= 2
Sqr(x, y) = g_Square(x, y)
x = x + 1
Wend
y = y + 1
Wend
Dim x2, y2
y = 0
While y <= 2
x = 0
While x <= 2
g_Square(y, 2 - x) = Sqr(x, y)
x = x + 1
Wend
y = y + 1
Wend
End Sub
'绘制下一方块
Sub DrawNextSquare()
Dim x As Integer, y As Integer
GamePage(0).Refresh
y = 0
While y <= 2
x = 0
While x <= 2
If g_NextSquare(x, y) Then
GamePage(0).PaintPicture ImgList.ListImages.Item(1).Picture, x * SQUARESIZE, y * SQUARESIZE
End If
x = x + 1
Wend
y = y + 1
Wend
End Sub
'确定方块矩阵最小范围
Sub CalSqrRange() '
'确定方块矩阵最小方形范围
'横向扫描
wy = 0
While wy <= 2
wx = 0
While wx <= 2
If g_Square(wx, wy) Then
SqrR.y = wy
GoTo Endy
End If
wx = wx + 1
Wend
wy = wy + 1
Wend
Endy:
'竖向扫描
wx = 0
While wx <= 2
wy = 0
While wy <= 2
If g_Square(wx, wy) Then
SqrR.x = wx
GoTo Endx
End If
wy = wy + 1
Wend
wx = wx + 1
Wend
Endx:
'横向扫描
wy = 2
While wy >= 0
wx = 0
While wx <= 2
If g_Square(wx, wy) Then
SqrR.ey = wy
GoTo Endey
End If
wx = wx + 1
Wend
wy = wy - 1
Wend
Endey:
'竖向扫描
wx = 2
While wx >= 0
wy = 0
While wy <= 2
If g_Square(wx, wy) Then
SqrR.ex = wx
GoTo Endex
End If
wy = wy + 1
Wend
wx = wx - 1
Wend
Endex:
End Sub
'方块矩阵翻转
Sub ChangeSqr()
Dim x As Integer, y As Integer
Dim Sqr(3, 3) As Boolean
y = 0
While y <= 2
x = 0
While x <= 2
Sqr(x, y) = g_Square(x, y)
x = x + 1
Wend
y = y + 1
Wend
Dim x2, y2
y = 0
While y <= 2
x = 0
While x <= 2
g_Square(y, 2 - x) = Sqr(x, y)
x = x + 1
Wend
y = y + 1
Wend
End Sub
'检测当前控制方块是否能处于某一位置
Function CanMove(x As Integer, y As Integer) As Boolean
Dim tx As Integer, ty As Integer
Dim xe As Integer, ye As Integer
'确定方块矩阵最小方形范围
CalSqrRange
If x + SqrR.x < 0 Then '左侧越界
CanMove = False
GoTo EndCanMove
ElseIf x + SqrR.ex > 10 Then '右侧越界
CanMove = False
GoTo EndCanMove
ElseIf y + SqrR.ey > 15 Then '下方越界
CanMove = False
GoTo EndCanMove
End If
'检测是否有方块冲突
ty = y + SqrR.y
While ty <= y + SqrR.ey
tx = x + SqrR.x
While tx <= x + SqrR.ex
If g_Site(tx, ty) And g_Square(tx - x, ty - y) Then
CanMove = False
GoTo EndCanMove
End If
tx = tx + 1
Wend
ty = ty + 1
Wend
CanMove = True
EndCanMove:
End Function
Private Sub Timer_Timer()
Dim x As Integer, y As Integer
Dim i As Integer
Dim SqrCount As Integer '一行方块计数
Dim DelCount As Integer '消除行数计数,用来计算分数
'消除方块
DelCount = 0
y = 15
While y >= 1
x = 0
SqrCount = 0
While x <= 10
If g_Site(x, y) Then
SqrCount = SqrCount + 1
End If
x = x + 1
Wend
If SqrCount = 11 Then '符合消除条件
i = y
While i >= 1
x = 0
While x <= 10
g_Site(x, i) = g_Site(x, i - 1)
x = x + 1
Wend
i = i - 1
Wend
DelCount = DelCount + 1
End If
y = y - 1
Wend
If DelCount = 1 Then
Grades.Caption = Str(Val(Grades.Caption) + 5)
ElseIf DelCount = 2 Then
Grades.Caption = Str(Val(Grades.Caption) + 12)
ElseIf DelCount > 2 Then
Grades.Caption = Str(Val(Grades.Caption) + DelCount * 10)
End If
If CanMove(g_SquarePosX, g_SquarePosY + 1) Then
g_SquarePosY = g_SquarePosY + 1 '方块下降一个单位
Else '方块固化
CalSqrRange
y = g_SquarePosY + SqrR.y
While y <= g_SquarePosY + 2
x = g_SquarePosX + SqrR.x
While x <= g_SquarePosX + 2 And x <= 10
g_Site(x, y) = g_Site(x, y) Or g_Square(x - g_SquarePosX, y - g_SquarePosY)
x = x + 1
Wend
y = y + 1
Wend
If g_SquarePosY + SqrR.y <= 1 Then
MsgBox "抱歉,你输了!"
Timer.Enabled = False
Else
y = 0
While y <= 2
x = 0
While x <= 2
g_Square(x, y) = g_NextSquare(x, y)
x = x + 1
Wend
y = y + 1
Wend
g_SquarePosX = 4
g_SquarePosY = 0
ProduceNextSqr
End If
End If
' GamePage(1).Refresh
Draw
' DrawSquare g_SquarePosX * SQUARESIZE, (g_SquarePosY - 2) * SQUARESIZE
End Sub