请高手帮我解释一下这段VB小游戏程序!高分赠送。
DimBallXAsIntegerDimBallYAsIntegerDimAddXAsIntegerDimAddYAsIntegerDimHitXAsIntegerDim...
Dim BallX As Integer
Dim BallY As Integer
Dim AddX As Integer
Dim AddY As Integer
Dim HitX As Integer
Dim W As Integer
Dim H As Integer
Private Sub Command1_Click()
BallX=Int(Rnd(1)*Form1.ScaleWidth/10)*5+25
BallY=Int((Form1.ScaleHeight)/10)*5
AddX=-5
AddY=-5
Form_Paint
Timer1.Enabled=True
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub Form_MouseMove(Button As Integer,Shift As Integer,X As Single,Y As Single)
X=X-50
If X<15 Then X=15
If X>W-105 Then X=W-105
HitX=X
If Timer1.Enabled=True Then
Line(16,H-5)-(W-6,H),&HC0C0C0,BF
Line(HitX,H)-(HitX+100,H-5),0,BF
End If
End Sub
Private Sub Form_Paint()
Cls
W=Int((ScaleWidth-140)/5)*5
H=Int((ScaleHeight-10)/5)*5
BackColor=&HC0C0C0
Line(10,10)-(15,H),0,BF
Line(W-5,10)-(W,H),0,BF
Line(10,10)-(W,15),0,BF
End Sub
Private Sub Timer1_Timer()
Form1.Circle(BallX,BallY),4,&HC0C0C0
BallX=BallX+AddX
BallY=BallY+AddY
Form1.Circle(BallX,BallY),4,0
If BallX<=20 Then AddX=-AddX
If BallY<=20 Then AddY=-AddY
If BallX>=W-10 Then AddX=-AddX
If BallY>=H-10 Then
If BallXHitX+100 Then
Timer1.Enabled=False
Form_Paint
End If
AddY=-AddY
End If
End Sub
尽量将每一行程序段进行解释,谢谢! 展开
Dim BallY As Integer
Dim AddX As Integer
Dim AddY As Integer
Dim HitX As Integer
Dim W As Integer
Dim H As Integer
Private Sub Command1_Click()
BallX=Int(Rnd(1)*Form1.ScaleWidth/10)*5+25
BallY=Int((Form1.ScaleHeight)/10)*5
AddX=-5
AddY=-5
Form_Paint
Timer1.Enabled=True
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub Form_MouseMove(Button As Integer,Shift As Integer,X As Single,Y As Single)
X=X-50
If X<15 Then X=15
If X>W-105 Then X=W-105
HitX=X
If Timer1.Enabled=True Then
Line(16,H-5)-(W-6,H),&HC0C0C0,BF
Line(HitX,H)-(HitX+100,H-5),0,BF
End If
End Sub
Private Sub Form_Paint()
Cls
W=Int((ScaleWidth-140)/5)*5
H=Int((ScaleHeight-10)/5)*5
BackColor=&HC0C0C0
Line(10,10)-(15,H),0,BF
Line(W-5,10)-(W,H),0,BF
Line(10,10)-(W,15),0,BF
End Sub
Private Sub Timer1_Timer()
Form1.Circle(BallX,BallY),4,&HC0C0C0
BallX=BallX+AddX
BallY=BallY+AddY
Form1.Circle(BallX,BallY),4,0
If BallX<=20 Then AddX=-AddX
If BallY<=20 Then AddY=-AddY
If BallX>=W-10 Then AddX=-AddX
If BallY>=H-10 Then
If BallXHitX+100 Then
Timer1.Enabled=False
Form_Paint
End If
AddY=-AddY
End If
End Sub
尽量将每一行程序段进行解释,谢谢! 展开
1个回答
展开全部
Dim BallX As Integer '小球的X轴坐标
Dim BallY As Integer '小球Y轴坐标
Dim AddX As Integer 'X轴增量
Dim AddY As Integer 'Y轴增量
Dim HitX As Integer '准星的X容距量
Dim W As Integer
Dim H As Integer
Private Sub Command1_Click()
BallX=Int(Rnd(1)*Form1.ScaleWidth/10)*5+25 '随机产生小球X坐标值
BallY=Int((Form1.ScaleHeight)/10)*5 '随机产生小球Y坐标值
AddX=-5 '小球左移5个单位(可能是像素)
AddY=-5 '小球上移5个单位
Form_Paint '窗体绘制事件
Timer1.Enabled=True '定时器激活
End Sub
Private Sub Command2_Click()
End '程序终止
End Sub
Private Sub Form_MouseMove(Button As Integer,Shift As Integer,X As Single,Y As Single) '鼠标移动事件
X=X-50 '设置鼠标(准星)与小球X坐标偏差
If X<15 Then X=15
If X>W-105 Then X=W-105
HitX=X '返回捕获X坐标值
If Timer1.Enabled=True Then '如果定时器状态为激活
'给制十字准星
Line(16,H-5)-(W-6,H),&HC0C0C0,BF
Line(HitX,H)-(HitX+100,H-5),0,BF
End If
End Sub
Private Sub Form_Paint()
Cls '清空窗口
'按窗口大小比例求十字准星长宽值
W=Int((ScaleWidth-140)/5)*5
H=Int((ScaleHeight-10)/5)*5
BackColor=&HC0C0C0 '设置背景色
Line(10,10)-(15,H),0,BF
Line(W-5,10)-(W,H),0,BF
Line(10,10)-(W,15),0,BF
End Sub
Private Sub Timer1_Timer() '定时器事件
Form1.Circle(BallX,BallY),4,&HC0C0C0 '定时画小球
BallX=BallX+AddX '小球位置偏移
BallY=BallY+AddY
Form1.Circle(BallX,BallY),4,0
If BallX<=20 Then AddX=-AddX
If BallY<=20 Then AddY=-AddY
If BallX>=W-10 Then AddX=-AddX
If BallY>=H-10 Then
If BallXHitX+100 Then
Timer1.Enabled=False
Form_Paint
End If
AddY=-AddY
End If
End Sub
Dim BallY As Integer '小球Y轴坐标
Dim AddX As Integer 'X轴增量
Dim AddY As Integer 'Y轴增量
Dim HitX As Integer '准星的X容距量
Dim W As Integer
Dim H As Integer
Private Sub Command1_Click()
BallX=Int(Rnd(1)*Form1.ScaleWidth/10)*5+25 '随机产生小球X坐标值
BallY=Int((Form1.ScaleHeight)/10)*5 '随机产生小球Y坐标值
AddX=-5 '小球左移5个单位(可能是像素)
AddY=-5 '小球上移5个单位
Form_Paint '窗体绘制事件
Timer1.Enabled=True '定时器激活
End Sub
Private Sub Command2_Click()
End '程序终止
End Sub
Private Sub Form_MouseMove(Button As Integer,Shift As Integer,X As Single,Y As Single) '鼠标移动事件
X=X-50 '设置鼠标(准星)与小球X坐标偏差
If X<15 Then X=15
If X>W-105 Then X=W-105
HitX=X '返回捕获X坐标值
If Timer1.Enabled=True Then '如果定时器状态为激活
'给制十字准星
Line(16,H-5)-(W-6,H),&HC0C0C0,BF
Line(HitX,H)-(HitX+100,H-5),0,BF
End If
End Sub
Private Sub Form_Paint()
Cls '清空窗口
'按窗口大小比例求十字准星长宽值
W=Int((ScaleWidth-140)/5)*5
H=Int((ScaleHeight-10)/5)*5
BackColor=&HC0C0C0 '设置背景色
Line(10,10)-(15,H),0,BF
Line(W-5,10)-(W,H),0,BF
Line(10,10)-(W,15),0,BF
End Sub
Private Sub Timer1_Timer() '定时器事件
Form1.Circle(BallX,BallY),4,&HC0C0C0 '定时画小球
BallX=BallX+AddX '小球位置偏移
BallY=BallY+AddY
Form1.Circle(BallX,BallY),4,0
If BallX<=20 Then AddX=-AddX
If BallY<=20 Then AddY=-AddY
If BallX>=W-10 Then AddX=-AddX
If BallY>=H-10 Then
If BallXHitX+100 Then
Timer1.Enabled=False
Form_Paint
End If
AddY=-AddY
End If
End Sub
11
2024-11-21 广告
2024-11-21 广告
VSIM软件模拟是上海允若信息科技有限公司提供的一项专业服务。我们利用VSIM软件,为客户提供高精度的模拟环境,帮助他们在虚拟空间中测试和验证各种复杂系统。无论是通信系统、网络系统还是其他工程系统,VSIM都能提供详尽的模拟结果,助力客户优...
点击进入详情页
本回答由11提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询