打砖块游戏代码
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Imports System.Drawing.Drawing2D
Public Class Form1
Public shuiping As Integer = 1
Public chuizhi As Integer = 1
Public WithEvents board As New Button
Public buttonList1 As New ArrayList()
Public ball As New Label
Public num As Integer
Public canDrag As Boolean = False
Dim x As Integer
Dim i As Integer = 0
'界面布置
Public Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load Me.Text = "张少霞制作2010242499"
'一些控制按钮
Button1.Left = 650
Button1.Top = 590
Button1.Text = "开始游戏"
Button2.Left = 750
Button2.Top = 590
Button2.Text = "暂停游戏"
Button3.Left = 650
Button3.Top = 625
Button3.Text = "分数"
Button4.Left = 750
Button4.Top = 625
Button4.Text = ""
GroupBox1.Left = 330
GroupBox1.Top = 590
'添加小球
ball.BackColor = System.Drawing.Color.Transparent
ball.ForeColor = System.Drawing.Color.Red
ball.Text = "●"
ball.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
ball.Width = 14
ball.Height = 14
ball.Left = 645
ball.Top = 539
Me.Controls.Add(ball)
'添加挡板
board.Width = 100
board.Height = 7
board.Left = 600 '330
board.Top = 553
board.BackColor = Color.Gray
Me.Controls.Add(board)
Button4.Text = 0
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick '小球的初始状态
ball.Left = ball.Left + shuiping * 7
ball.Top = ball.Top + chuizhi * 7
Dim a As Integer
a = ball.Left + 7
Dim b As Integer
b = ball.Top + 7
Button4.Text = 66 - num
'判断小球是否和砖块碰撞
For Each ctl In buttonList1
If ((a - 7 >= ctl.Left And a - 7 <= ctl.Right) Or (a + 7 >= ctl.Left And a + 7 <= ctl.Right)) And (b >= ctl.Top And b <= ctl.Bottom) Then
shuiping = -shuiping
Me.Controls.Remove(ctl)
num = num - 1
Exit For
ElseIf ((b - 7 >= ctl.Top And b - 7 <= ctl.Bottom) Or (b + 7 >= ctl.Top And b + 7 <= ctl.Bottom)) And (a >= ctl.Left And a <= ctl.Right) Then
chuizhi = -chuizhi
Me.Controls.Remove(ctl)
num = num - 1
Exit For
End If
Next
'判断小球是否和边界碰撞
If (a - 7 <= Me.Left And a + 7 >= Me.Left) Or (a + 7 >= Me.ClientSize.Width And a - 7 <= Me.ClientSize.Width) Then
shuiping = -shuiping
End If
'判断小球是否和挡板碰撞
If ((b + 7 >= board.Top And b + 7 <= board.Bottom) And (a >= board.Left And a <= board.Right)) Or (b - 7 <= 0 And b + 7 >= 0) Then
chuizhi = -chuizhi
End If
'当挡板没有借住小球时予以提示(三次机会)
If ((board.Top <= b + 7 And b + 7 <= board.Top + board.Height) And (a + 7 <= board.Left Or a - 7 >= board.Right)) Then