VB.NET写的566行俄罗斯方块,带注释哦
看到xiaoshenyi2贴了个C#的俄罗斯方块,我也贴一个大二时候写的俄罗斯方块凑个热闹
Public Class frmgame
'OIZLT
Public sign(10, 20) As Integer
Public active(10, 20) As Boolean
Public activemove(10, 20) As Boolean
Public lbcell(10, 20) As Label
Public figuretype As Integer
Public drawx As Integer, drawy As Integer
WithEvents figurefalldown As New Timer
Private Sub frmgame_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.Left Then Call lmove()
If e.KeyCode = Keys.Right Then Call rmove()
If e.KeyCode = Keys.Down Then Call fastdown()
If e.KeyCode = Keys.Space Or e.KeyCode = Keys.Up Then
If init(figuretype) = False Then
Call rollfigure(drawx, drawy)
End If
End If
End Sub
Private Sub frmgame_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Randomize()
Call loadlbcell()
Call creatfigure(Fix(Rnd() * 19) + 1)
figurefalldown.Enabled = True
figurefalldown.Interval = 1000
Me.AutoSize = True
End Sub
Public Function loadlbcell()
For i As Integer = 0 To 9
For o As Integer = 0 To 19
lbcell(i, o) = New Label
With lbcell(i, o)
.Name = "lbcell" & i & "," & o
.Width = 13
.Height = 13
.Left = 15 * i + 15
.Top = 15 * o + 10
.BackColor = Color.White
End With
Me.Controls.Add(lbcell(i, o))
Next
Next
Return 0
End Function '创建用于显示方块的label
Public Function updatacell()
For i As Integer = 0 To 9
For o As Integer = 0 To 19
If active(i, o) = True Or activemove(i, o) = True Then
lbcell(i, o).BackColor = Color.Black
Else
lbcell(i, o).BackColor = Color.White
End If
Next
Next
Return 0
End Function '更新格子显示
Public Function clearactivemove(ByVal ParamArray temp() As Object)
For i As Integer = 0 To 9
For o As Integer = 0 To 19
activemove(i, o) = False
Next
Next
Return 0
End Function '清除当前处于移动状态的cell的标志,为下一次移动初始化
Public Function creatfigure(ByVal figtype As Integer)
Randomize()
clearactivemove()
Select Case figtype
Case 1 'O
figuretype = 1
drawx = 4 : drawy = 0
activemove(4, 0) = True : activemove(5, 0) = True
activemove(4, 1) = True : activemove(5, 1) = True
Case 2 'I
figuretype = 2
drawx = 5 : drawy = 1
activemove(5, 0) = True
activemove(5, 1) = True
activemove(5, 2) = True
activemove(5, 3) = True
Case 3 '一
figuretype = 3
drawx = 5 : drawy = 0
activemove(3, 0) = True : activemove(4, 0) = True : activemove(5, 0) = True : activemove(6, 0) = True
Case 4 'Z
figuretype = 4
drawx = 5 : drawy = 0
activemove(4, 0) = True : activemove(5, 0) = True
activemove(5, 1) = True : activemove(6, 1) = True '->
Case 5 'Z2
figuretype = 5
drawx = 6 : drawy = 1
activemove(6, 0) = True '->
activemove(5, 1) = True : activemove(6, 1) = True
activemove(5, 2) = True
Case 6 '反Z
figuretype = 6
drawx = 5 : drawy = 0
activemove(5, 0) = True : activemove(6, 0) = True '->
activemove(4, 1) = True : activemove(5, 1) = True
Case 7 '反Z2
figuretype = 7
drawx = 5 : drawy = 1
activemove(5, 0) = True
activemove(5, 1) = True : activemove(6, 1) = True
activemove(6, 2) = True '->
Case 8 'L
figuretype = 8
drawx = 4 : drawy = 1
activemove(4, 0) = True
activemove(4, 1) = True
activemove(4, 2) = True : activemove(5, 2) = True
Case 9 'L2
figuretype = 9
drawx = 5 : drawy = 0
activemove(4, 0) = True : activemove(5, 0) = True : activemove(6, 0) = True
activemove(4, 1) = True
Case 10 'L3
figuretype = 10
drawx = 6 : drawy = 1
activemove(5, 0) = True : activemove(6, 0) = True
activemove(6, 1) = True '->
activemove(6, 2) = True '->
Case 11 'L4
figuretype = 11
drawx = 5 : drawy = 1
activemove(6, 0) = True '-->
activemove(4, 1) = True : activemove(5, 1) = True : activemove(6, 1) = True
Case 12 '反L
figuretype = 12
drawx = 6 : drawy = 1
activemove(6, 0) = True '->
activemove(6, 1) = True '->
activemove(5, 2) = True : activemove(6, 2) = True
Case 13 '反L2
figuretype = 13
drawx = 5 : drawy = 1
activemove(4, 0) = True
activemove(4, 1) = True : activemove(5, 1) = True : activemove(6, 1) = True
Case 14 '反L3
figuretype = 14
drawx = 5 : drawy = 1
activemove(5, 0) = True : activemove(6, 0) = True
activemove(5, 1) = True
activemove(5, 2) = True
Case 15 '反L4
figuretype = 15
drawx = 5 : drawy = 0
activemove(4, 0) = True : activemove(5, 0) = True : activemove(6, 0) = True
activemove(6, 1) = True '-->
Case 16 'T
figuretype = 16
drawx = 5 : drawy = 0
activemove(4, 0) = True : activemove(5, 0) = True : activemove(6, 0) = True
activemove(5, 1) = True '->
Case 17 'T2
figuretype = 17
drawx = 6 : drawy = 1
activemove(6, 0) = True '->
activemove(5, 1) = True : activemove(6, 1) = True
activemove(6, 2) = True '->
Case 18 'T3
figuretype = 18
drawx = 5 : drawy = 1
activemove(5, 0) = True '->
activemove(4, 1) = True : activemove(5, 1) = True : activemove(6, 1) = True
Case 19 'T4
figuretype = 19
drawx = 5 : drawy = 1
activemove(5, 0) = True
activemove(5, 1) = True : activemove(6, 1) = True
activemove(5, 2) = True
End Select
updatacell()
Return 0
End Function '创建一个图形,设置figuretype,activemove
Public Function lmove()
For i As Integer = 0 To 9
For o As Integer = 0 To 19
If activemove(i, o) = True Then
If i = 0 Then Return 0 : Exit Function
activemove(i - 1, o) = True : activemove(i, o) = False
drawx -= 1
End If
Next
Next
drawx += 3
Me.Text = drawx & "," & drawy
updatacell()
Return 0
End Function '向左移动图形
Public Function rmove()
For i As Integer = 9 To 0 Step -1
For o As Integer = 19 To 0 Step -1
If activemove(i, o) = True Then
If i = 9 Then Return 0 : Exit Function
activemove(i + 1, o) = True : activemove(i, o) = False
drawx += 1
End If
Next
Next
drawx -= 3
Me.Text = drawx & "," & drawy
updatacell()
Return 0
End Function '向右移动图形
Public Function dmove()
For i As Integer = 9 To 0 Step -1
For o As Integer = 19 To 0 Step -1
If activemove(i, o) = True Then
activemove(i, o + 1) = True : activemove(i, o) = False
End If
Next
Next
drawy += 1
Me.Text = drawx & "," & drawy
updatacell()
Return 0
End Function '向下移动图形