我寫來的遊戲,全部源代碼:
Dim?vx?As?Integer,?vy?As?Integer
Dim?tm?As?Integer
Dim?fs?As?Integer
Private?Sub?Command1_Click()
If?Timer1.Enabled?=?False?Then
Timer1.Enabled?=?True
If?Shape2.Top?>?Picture1.Height?Then
Dim?x?As?Integer
x?=?0
Shape1.Left?=?Picture1.Width?/?2?-?Shape1.Width?/?2
Shape1.Top?=?Picture1.Height?-?300
Shape2.Left?=?Picture1.Width?/?2?-?Shape2.Width?/?2
Shape2.Top?=?Picture1.Height?-?Shape1.Height?-?Shape1.Height?-?50
vx?=?30
vy?=?30
'Label1(0).Visible?=?False
'For?i?=?1?To?90?Step?2
'Unload?Label1(i)
'Next?i
'For?i?=?1?To?90?Step?2
'Load?Label1(i)
'Label1(i).Visible?=?True
'Label1(i).Caption?=?""
'Label1(i).Left?=?375?*?((i?-?1)?Mod?15)
'Label1(i).Top?=?135?*?x
'?If?i?Mod?15?=?0?Or?i?Mod?15?=?14?Then
'x?=?x?+?1
'End?If'Next?i
End?If
End?If
End?Sub
Private?Sub?Command2_Click()
End
End?Sub
Private?Sub?Form_Load()
Label2.Caption?=?"還剩"?&?3?&?"盤"
Label1(0).Visible?=?False
Shape1.Left?=?Picture1.Width?/?2?-?Shape1.Width?/?2
Shape1.Top?=?Picture1.Height?-?300
Shape2.Left?=?Picture1.Width?/?2?-?Shape2.Width?/?2
Shape2.Top?=?Picture1.Height?-?Shape1.Height?-?Shape1.Height?-?50
vx?=?30
vy?=?30
Call?rnk1
Label4.Caption?=?"第1關"
End?Sub
Private?Sub?Picture1_KeyDown(KeyCode?As?Integer,?Shift?As?Integer)
If?KeyCode?=?37?Then
If?Shape1.Left?>?0?Then
Shape1.Left?=?Shape1.Left?-?50
End?If
ElseIf?KeyCode?=?39?Then
If?Shape1.Left?<?Picture1.Width?-?Shape1.Width?Then
Shape1.Left?=?Shape1.Left?+?50
End?If
End?If
End?Sub
Private?Sub?Timer1_Timer()
Shape2.Left?=?Shape2.Left?+?vx
Shape2.Top?=?Shape2.Top?-?vy
If?Shape2.Left?>?Picture1.Width?-?Shape2.Width?Then?vx?=?-vx
If?Shape2.Top?<?0?Then?vy?=?-vy?'Picture1.Height?-?500?Then
If?Shape2.Left?<?0?Then?vx?=?-vx?'Picture1.Left?Then?vx?=?-vx
If?Shape2.Top?>?Picture1.Height?-?Shape1.Height?-?Shape2.Height?And?Shape2.Top?<?Picture1.Height?-?Shape1.Height?-?Shape2.Height?+?100?Then
If?Shape2.Left?>?Shape1.Left?And?Shape2.Left?<?Shape1.Left?+?Shape1.Width?Then vy?=?-vy Else vx?=?vy End?If End?If If?Shape2.Top?>=?Picture1.Height?ThenTimer1.Enabled?=?False
tm?=?tm?+?1 Label2.Caption?=?"還剩"?&?3?-?tm?&?"盤" If?tm?=?3?ThenMsgBox?"Game?Over!",?vbOKOnly,?"遊戲結束"
Command1.Enabled?=?False
End?If End?If For?i?=?1?To?90 If?Label1(i).Visible?=?True?ThenIf?Shape2.Left?>?Label1(i).Left?-?Shape2.Width?And?Shape2.Left?<?Label1(i).Left?+?Label1(i).Width?Then
If?Shape2.Top?<=?Label1(i).Top?+?Label1(i).Height?Then If?Label1(i).Visible?=?True?Then vy?=?-vy fs?=?fs?+?1 Label3.Caption?=?fs?&?"分" For?j?=?1?To?90 If?Label1(j).Visible?=?True?ThenGoTo?xx?'Exit?For
Else If?j?=?90?Thenx?=?x?+?1
Label4.Caption?=?"第"?&?Str(x?+?1)?&?"關"
If?x?=?2?Then
Call?rnk2Shape1.Left?=?Picture1.Width?/?2?-?Shape1.Width?/?2
Shape1.Top?=?Picture1.Height?-?300
Shape2.Left?=?Picture1.Width?/?2?-?Shape2.Width?/?2
Shape2.Top?=?Picture1.Height?-?Shape1.Height?-?Shape1.Height?-?50
Timer1.Enabled?=?False
ElseIf?x?=?3?Then
Call?rnk3 Shape1.Left?=?Picture1.Width?/?2?-?Shape1.Width?/?2Shape1.Top?=?Picture1.Height?-?300
Shape2.Left?=?Picture1.Width?/?2?-?Shape2.Width?/?2
Shape2.Top?=?Picture1.Height?-?Shape1.Height?-?Shape1.Height?-?50
Timer1.Enabled?=?False
End?If
End?If
End?Ifxx:
Next?j End?If Label1(i).Visible?=?False 'Unload?Label1(i) Exit?For End?If End?If End?If Next?iEnd?Sub
module1:
Dim?x?As?Integer
Public?Sub?rnk1()
For?i?=?1?To?90
On?Error?Resume?Next
Unload?form1.Label1(i)
Next?i
x?=?0
For?i?=?1?To?90
Load?form1.Label1(i)
If?i?Mod?2?=?0?Then
form1.Label1(i).Visible?=?False Elseform1.Label1(i).Visible?=?True
form1.Label1(i).BackColor?=?RGB(Int(Rnd?*?255),?Int(Rnd?*?255),?Int(Rnd?*?255))
form1.Label1(i).Caption?=?""
form1.Label1(i).Left?=?375?*?((i?-?1)?Mod?15)
form1.Label1(i).Top?=?135?*?x
If?i?Mod?15?=?0?Or?i?Mod?15?=?14?Thenx?=?x?+?1
End?IfEnd?If
Next?i
End?Sub
Public?Sub?rnk2()
Dim?x?As?Integer,?i?As?Integer
For?i?=?1?To?90
Load?form1.Label1(i)
If?i?\?15?>?3?Then x?=?5?-?i?\?15 Else x?=?i?\?15 End?IfIf?i?Mod?15?<=?2?*?x?+?1?Or?i?Mod?15?>=?15?-?2?*?x?+?1?Then
'If?i?>?2?Or?i?=?1?Then
form1.Label1(i).Visible?=?False Else form1.Label1(i).Visible?=?Trueform1.Label1(i).BackColor?=?RGB(Int(Rnd?*?255),?Int(Rnd?*?255),?Int(Rnd?*?255))
form1.Label1(i).Caption?=?""
form1.Label1(i).Left?=?375?*?((i?-?1)?Mod?15)
form1.Label1(i).Top?=?135?*?(i?\?15)
If?i?Mod?15?=?0?Or?i?Mod?15?=?14?Thenx?=?x?+?1
End?If End?If Next?iEnd?Sub
Public?Sub?rnk3()
'
End?Sub