求VB课程设计
- 提问者网友:嗝是迷路的屁
- 2021-03-17 12:13
- 五星知识达人网友:duile
- 2021-03-17 12:26
代码:
Dim x11 As Double
Dim x22 As Double
Dim y11 As Double
Dim y22 As Double
Dim m As Boolean
Dim j As Integer
Dim l As Integer
Private Sub Command1_Click()
Timer1.Interval = 100
Command1.Visible = False
End Sub
Private Sub Form_Load()
MsgBox "在窗体里点击左键不放来改变射击方向,释放左键后射击"
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim temp As Double
If Line1.X1 < Line1.X2 Then
Line1.Y1 = Line1.Y2 - Line1.X2 * (Line1.Y2 - Line1.Y1) / (Line1.X2 - Line1.X1)
Line1.X1 = 0
For i = 0 To 6
temp = Line1.X2 - (Line1.X2 - Line1.X1) * (Line1.Y2 - Shape1(i).Top) / (Line1.Y2 - Line1.Y1)
If temp >= Shape1(i).Left And temp <= Shape1(i).Left + Shape1(i).Width Then
m = True
j = i
l = Shape1(i).Left
Me.Caption = Split(Me.Caption, "分")(0) + 1 & "分"
Exit For
End If
Next
Timer2.Interval = 500
Else
Line1.Y1 = Line1.Y2 - (Form1.Width - Line1.X2) * (Line1.Y2 - Line1.Y1) / (Line1.X1 - Line1.X2)
Line1.X1 = Form1.Width
For i = 0 To 6
temp = Line1.X2 + (Line1.X1 - Line1.X2) * (Line1.Y2 - Shape1(i).Top) / (Line1.Y2 - Line1.Y1)
If temp >= Shape1(i).Left And temp <= Shape1(i).Left + Shape1(i).Width Then
m = True
j = i
l = Shape1(i).Left
Me.Caption = Split(Me.Caption, "分")(0) + 1 & "分"
Exit For
End If
Next
Timer2.Interval = 500
End If
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
Line1.X1 = X
x11 = Line1.X1
x22 = Line1.X2
y11 = Line1.Y1
y22 = Line1.Y2
End If
End Sub
Private Sub Timer1_Timer()
Shape1(0).Left = IIf(Shape1(0).Left >= Form1.Width, 0, Shape1(0).Left + 100)
Shape1(1).Left = IIf(Shape1(1).Left >= Form1.Width, 0, Shape1(1).Left + 150)
Shape1(2).Left = IIf(Shape1(2).Left >= Form1.Width, 0, Shape1(2).Left + 200)
Shape1(3).Left = IIf(Shape1(3).Left >= Form1.Width, 0, Shape1(3).Left + 160)
Shape1(4).Left = IIf(Shape1(4).Left >= Form1.Width, 0, Shape1(4).Left + 90)
Shape1(5).Left = IIf(Shape1(5).Left >= Form1.Width, 0, Shape1(5).Left + 210)
Shape1(6).Left = IIf(Shape1(6).Left >= Form1.Width, 0, Shape1(6).Left + 260)
End Sub
Private Sub Timer2_Timer()
Line1.X1 = 4080
Line1.X2 = 4080
Line1.Y1 = 3960
Line1.Y2 = 4680
Timer2.Interval = 0
End Sub
Private Sub Timer3_Timer()
If m = True Then Shape1(j).Top = Shape1(j).Top + 100: Shape1(j).Left = l
If Shape1(j).Top > Form1.Height + 200 Then m = False
End Sub
- 1楼网友:冷風如刀
- 2021-03-17 13:07
' private declare function showcursor lib "user32" (byval bshow as long) as long private declare sub sleep lib "kernel32" (byval dwmilliseconds as long) dim cor(3)
private sub form_keydown(keycode as integer, shift as integer) unload me end sub
private sub form_load() me.borderstyle = 0 me.backcolor = &h80000008 timer1.interval = 30 timer2.interval = 30 if app.previnstance = true then end '如果该程序在运行则结束当前程序 me.move 0, 0, screen.width, screen.height showcursor false '隐藏鼠标 end sub
private sub form_mousedown(button as integer, shift as integer, x as single, y as single) unload me end sub
'private sub form_mousemove(button as integer, shift as integer, x as single, y as single) 'if timer1.enabled = true then exit sub 'unload me 'end sub
private sub form_unload(cancel as integer) showcursor true end end sub
private sub timer1_timer()
timer1.enabled = false randomize timer dim x1(3), y1(3), x2(3), y2(3), x3(3), y3(3), x4(3), y4(3), a1(3), b1(3), c1(3), d1(3), a2(3), b2(3), c2(3), d2(3) for i = 1 to 3 x1(i) = rnd * me.scalewidth y1(i) = rnd * me.scaleheight x2(i) = rnd * me.scalewidth y2(i) = rnd * me.scaleheight x3(i) = rnd * me.scalewidth y3(i) = rnd * me.scaleheight x4(i) = rnd * me.scalewidth y4(i) = rnd * me.scaleheight cor(i) = rgb(rnd * 255, rnd * 255, rnd * 255) next for i = 1 to 3 a1(i) = 2 a2(i) = 1 b1(i) = 2 b2(i) = 1 c1(i) = 1 c2(i) = 2 d1(i) = 1 d2(i) = 2 next do doevents for n = 1 to 3 line (x1(n), y1(n))-(x2(n), y2(n)), cor(n) line (x2(n), y2(n))-(x3(n), y3(n)), cor(n) line (x3(n), y3(n))-(x4(n), y4(n)), cor(n) line (x4(n), y4(n))-(x1(n), y1(n)), cor(n) next for n = 1 to 3 if x1(n) > me.scalewidth or x1(n) < 0 then a1(n) = -a1(n) if y1(n) > me.scaleheight or y1(n) < 0 then a2(n) = -a2(n) if x2(n) > me.scalewidth or x2(n) < 0 then b1(n) = -b1(n) if y2(n) > me.scaleheight or y2(n) < 0 then b2(n) = -b2(n) if x3(n) > me.scalewidth or x3(n) < 0 then c1(n) = -c1(n) if y3(n) > me.scaleheight or y3(n) < 0 then c2(n) = -c2(n) if x4(n) > me.scalewidth or x4(n) < 0 then d1(n) = -d1(n) if y4(n) > me.scaleheight or y4(n) < 0 then d2(n) = -d2(n) next sleep 0.51 cls for n = 1 to 3 x1(n) = x1(n) + a1(n) y1(n) = y1(n) - a2(n) x2(n) = x2(n) + b1(n) y2(n) = y2(n) + b2(n) x3(n) = x3(n) + c1(n) y3(n) = y3(n) - c2(n) x4(n) = x4(n) + d1(n) y4(n) = y4(n) = d2(n) next doevents loop end sub
private sub timer2_timer() for j = 1 to 3 doevents cor(j) = rgb(rnd * 255, rnd * 255, rnd * 255) doevents next
end sub
窗体弄成黑色的就行,你试试吧