当前位置:编程学习 > VB >>

VB写俄罗斯方块!VB 高手进。

我想用VB编一个俄罗斯方块。。求各位大虾帮帮忙。。。最好是所有步骤。。
答案:Public Class Form1
Dim new_p, old_p As ToolStripMenuItem '设置级别
Public interval As Integer
Public check(7, 15) As Boolean
Dim panel2(4) As Point
Dim intSquareStyle As Integer
Dim oldSquareStyle As Integer

Private Sub mypanel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles mypanel1.Paint
Dim i As Integer
Dim j As Integer
For i = 0 To 7
For j = 0 To 15
If check(i, j) Then
DrawSquare(i, j, mypanel1)
End If
Next
Next
End Sub

Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Dim intResponse As Integer
Timer1.Enabled = False
intResponse = MessageBox.Show("是否要保存应用程序?", "俄罗斯方块", MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1)
If intResponse = vbYes Then
Dim i, j As Integer
WritePrivateProfileString("俄罗斯方块", "Score", Label2.Text, Application.StartupPath & "\app.ini")
For i = 0 To 7
For j = 0 To 15
WritePrivateProfileString("俄罗斯方块", "check" & CStr(i) & CStr(j), IIf(check(i, j), "1", "0").ToString, Application.StartupPath & "\app.ini")
Next
Next
WritePrivateProfileString("俄罗斯方块", "jibie", old_p.Tag.ToString, Application.StartupPath & "\app.ini")
For i = 0 To 3
WritePrivateProfileString("俄罗斯方块", "NewSquares" & CStr(i) & "X", SquresBase.Squares(i).X.ToString, Application.StartupPath & "\app.ini")
WritePrivateProfileString("俄罗斯方块", "NewSquares" & CStr(i) & "Y", SquresBase.Squares(i).Y.ToString, Application.StartupPath & "\app.ini")
Next i
WritePrivateProfileString("俄罗斯方块", "symmetryX", SquresBase.symmetry.X.ToString, Application.StartupPath & "\App.ini")
WritePrivateProfileString("俄罗斯方块", "symmetryY", SquresBase.symmetry.Y.ToString, Application.StartupPath & "\App.ini")
WritePrivateProfileString("俄罗斯方块", "SquareStyle", oldSquareStyle.ToString, Application.StartupPath & "\App.ini")
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
frmStart.ShowDialog()
If frmStart.newGame Then
interval = 400
Timer1.Interval = interval
old_p = 低级ToolStripMenuItem
old_p.Checked = True
Label2.Text = "0"
Else
' the score is 0
Dim i, j As Integer
Dim s As String = "10"
' GetPrivateProfileString("abc", "Score", "0", Label2.Text, 256, Application.StartupPath & "\App.ini")
GetPrivateProfileString("俄罗斯方块", "Score", "10", s, 256, Application.StartupPath & "\App.ini")

Label2.Text = s
For i = 0 To 7
For j = 0 To 15
GetPrivateProfileString("俄罗斯方块", "check" & CStr(i) & CStr(j), "0", s, 256, Application.StartupPath & "\app.ini")
check(i, j) = CBool(IIf(CInt(s) = 1, True, False))
Next
Next
buttom = mypanel1.Height()
Dim jibie As String = " "
GetPrivateProfileString("俄罗斯方块", "jibie", "3", jibie, 256, Application.StartupPath & "\App.ini")
Dim TSM As ToolStripMenuItem
For Each TSM In GameToolStripMenuItem.DropDownItems
If TSM.Tag.ToString = CInt(Trim(jibie)).ToString Then
old_p = TSM
Exit For
Else
old_p = 低级ToolStripMenuItem
End If
Next
Dim Strinterval As String = " "
GetPrivateProfileString("俄罗斯方块", "inteval", "400", Strinterval, 256, Application.StartupPath & "\App.ini")
interval = CInt(Trim(Strinterval))
Timer1.Interval = interval
If Not old_p Is 低级ToolStripMenuItem Then
低级ToolStripMenuItem.Checked = False
End If
old_p.Checked = True
'构造方块
newSquares = New SquresBase
Dim str As String
For i = 0 To 3
str = " "
GetPrivateProfileString("俄罗斯方块", "NewSquares" & CStr(i) & "X", "2", str, 256, Application.StartupPath & "\App.ini")
SquresBase.Squares(i).X = CInt(Trim(str))
str = " "
GetPrivateProfileString("俄罗斯方块", "NewSquares" & CStr(i) & "Y", "0", str, 256, Application.StartupPath & "\App.ini")
SquresBase.Squares(i).Y = CInt(Trim(str))
Next
str = " "
GetPrivateProfileString("俄罗斯方块", "symmetryX", "0", str, 256, Application.StartupPath & "\App.ini")
SquresBase.symmetry.X = CInt(Trim(str))
str = " "
GetPrivateProfileString("俄罗斯方块", "symmetryY", "0", str, 256, Application.StartupPath & "\App.ini")
SquresBase.symmetry.Y = CInt(Trim(str))
str = " "
GetPrivateProfileString("俄罗斯方块", "SquareStyle", "0", str, 256, Application.StartupPath & "\App.ini")
oldSquareStyle = CInt(Trim(str))
End If

End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Timer1.Stop()
mypanel1.Focus()
newSquares.MoveDown()
Timer1.Start()
End Sub
Private Sub ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 开始ToolStripMenuItem.Click, 低级ToolStripMenuItem.Click, 高级ToolStripMenuItem.Click, ToolStripMenuItem2.Click, 中级ToolStripMenuItem1.Click
Dim tempMenuItem As ToolStripMenuItem
tempMenuItem = CType(sender, ToolStripMenuItem)
Dim temp As Int32
temp = CInt(tempMenuItem.Tag)
Select Case temp
Case 0
'advance
new_p = tempMenuItem
Timer1.Interval = 100
Case 1
'normal
new_p = tempMenuItem
Timer1.Interval = 300
Case 2
'easy
new_p = tempMenuItem
Timer1.Interval = 400
Case 3
'start
Dim i, j As Integer
For j = 0 To 15
For i = 0 To 7
If check(i, j) Then
Timer1.Start()
createpanel2()
Exit Sub
End If
Next
Next
Start()
Exit Sub
Case 4
'restarted
restarted()
Exit Sub
End Select
inteval = Timer1.Interval
old_p.Checked = False
new_p.Checked = True
old_p = new_p
End Sub

Private Sub DrawSquare(ByVal x As Integer, ByVal y As Integer, ByVal panel As Panel)
Randomize()
Dim myBrush As New System.Drawing.SolidBrush(Color.AliceBlue)
Dim panelGraphics As System.Drawing.Graphics
panelGraphics = panel.CreateGraphics
panelGraphics.FillRectangle(myBrush, New Rectangle(x * IntSize, y * IntSize, IntSize, IntSize))
panelGraphics.DrawRectangle(Pens.LightBlue, New Rectangle(x * IntSize, y * IntSize, 16, 16))
panelGraphics.DrawRectangle(Pens.Blue, New Rectangle(x * IntSize + 2, y * IntSize + 2, 12, 12))
panelGraphics.DrawRectangle(Pens.DarkBlue, New Rectangle(x * IntSize + 4, y * IntSize + 4, 8, 8))
panelGraphics.FillRectangle(New System.Drawing.SolidBrush(Color.SkyBlue), New Rectangle(x * IntSize + 4, y * IntSize + 4, 8, 8))
myBrush.Dispose()
panelGraphics.Dispose()
If panel Is mypanel1 Then
check(x, y) = True
End If
End Sub
Private Sub DrawSquares(ByVal panel As Panel)
Dim i As Integer
For i = 0 To 3
DrawSquare(Squares(i).X, Squares(i).Y, panel)
Next
End Sub

高哇,别人给你用VB写一个,你自己去改成VB.NET呀?

大学学过VB编程,现在全忘记了,没法帮你了

上一个:求助VB编程高手关于数据库连接的方法
下一个:VB数据处理高手来帮下忙

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,