看到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