高手进来看看
vb.net吧
全部回复
仅看楼主
level 2
qq5646948 楼主
Public Class Form1
Private Score As Integer = 0
Private Vx As Double = 5
Private Vy As Double = 5
Private MDx As Integer Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.BackColor = Color.FromArgb(204, 232, 207)
End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
B.Left += Vx
B.Top += Vy
If B.Left < 0 Then
Vx = Math.Abs(Vx)
End If
If B.Right > Me.ClientSize.Width Then
Vx = -Math.Abs(Vx)
End If
If B.Top < 0 Then
Vy = Math.Abs(Vy)
End If
If B.Bottom > P.Top Then
Dim C As Integer = (B.Left + B.Right) / 2
If C >= P.Left AndAlso C <= P.Right Then
Dim F As Double = (CDbl(C) - CDbl(P.Left)) / CDbl(P.Width)
If Vx < 0 Then
F = (1.0 - F)
End If
F = F + 0.5
Vx = CInt(Math.Round(Vx * F))
Vy = -Math.Abs(Vy)
Score = Score + 10
Me.Text = "分数:" & Score.ToString()
Else
If B.Bottom > Me.ClientSize.Height Then
Timer1.Stop()
MsgBox("Game Over!", , "提示")
B.Left = 220
B.Top = 200
Score = 0
Vx = 5
Vy = 5
Me.Text = "分数:" & Score.ToString()
End If
End If
End If
End Sub Private Sub P_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles P.MouseDown
Timer1.Start()
Cursor.Current = Cursors.Hand
MDx = e.X
End Sub Private Sub P_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs) Handles P.MouseMove
If e.Button = MouseButtons.Left Then
Dim x As Integer = P.Left + (e.X - MDx)
If x < 0 Then
x = 0
End If
If x > Me.ClientSize.Width - P.Width Then
x = Me.ClientSize.Width - P.Width
End If
P.Left = x
End If
End Sub End Class
能不能解释下代码里的private Vx,Vy,MDx,分别代表什么意思。 如果可以的能不能插点解释,大概每段代码是什么意思。谢谢拉
2013年05月16日 00点05分 1
level 2
qq5646948 楼主
还有图中的球代表B,条状代表P。。
2013年05月16日 00点05分 2
level 2
qq5646948 楼主
2013年05月16日 01点05分 3
level 2
qq5646948 楼主
这游戏是前面有人发过的。。想学习一下。
2013年05月16日 01点05分 4
level 6
Vx是球的x速度
Vy是y速度
MDx是鼠标点下位置的x
2013年05月16日 02点05分 5
If B.Left < 0 Then Vx = Math.Abs(Vx) End If If B.Right > Me.ClientSize.Width Then Vx = -Math.Abs(Vx) End If If B.Top < 0 Then Vy = Math.Abs(Vy) End If
2013年05月16日 20点05分
If B.Bottom > P.Top Then Dim C As Integer = (B.Left + B.Right) / 2 If C >= P.Left AndAlso C <= P.Right Then Dim F As Double = (CDbl(C) - CDbl(P.Left)) / CDbl(P.Width)
2013年05月16日 20点05分
If Vx < 0 Then F = (1.0 - F) End If F = F + 0.5 Vx = CInt(Math.Round(Vx * F)) Vy = -Math.Abs(Vy). 能不能帮我解释下这段的意思C和f分别为什么?。。还有后面2个private sub。
2013年05月16日 20点05分
回复 qq5646948 :上面两个回复是关于球超过边界即将x或y速度反向实现反弹效果。下面那个我不知道干什么的 如果只给出部分代码的话。这种用两三个字母命名变量的编程习惯非常不好!VB.Net惯用的变量明一般是n个单词组合,每个单词首字母大写。比如MDx写成这样:MouseDownXRecord
2013年05月16日 23点05分
level 2
qq5646948 楼主
C和f分别为什么?
2013年05月16日 13点05分 7
C是球的中心点的x坐标; F是一个。。。比例系数。。。球弹在板上相对板子的位置,程序通过F的值判定球反弹的方向
2013年05月17日 00点05分
回复 sleepwalking :喔!!非常感谢!
2013年05月17日 01点05分
level 3
...
2013年05月17日 04点05分 8
1