射擊 遊戲
-
Upload
amela-herring -
Category
Documents
-
view
22 -
download
0
description
Transcript of 射擊 遊戲
射擊遊戲 南台科技大學 機械工程系 自動化控制組 學號 :4A212110
沈冠維
產品動機
做這個遊戲的目的是,希望在空閒的時間可以和朋友有一個可以打發時間的遊戲或是可以永朋友促進友誼關係。
遊戲玩法說明
分數和時間隨機出現標靶
程式碼說明 01
Dim CircleX, CircleY
02
Private Sub Command1_Click()
03
Command1.Enabled = False ' 禁止重複按 04
Label1.Caption = 20 ' 時間 05
Label2.Caption = 0 ' 分數 06
Timer1.Enabled = True ' 啟動倒數計時 07
Timer2.Enabled = True ' 啟動標靶 08
End Sub
程式碼說明 09
10
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
11
' 數學公式: (H-X)^2 + (K-Y)^2 <= R^2 等於點的位置在 半徑 R 範圍裡面 12
If ((CircleX - X) ^ 2 + (CircleY - Y) ^ 2) <= 300 ^ 2 Then Label2 = Label2 + 8 ' 在範圍 300 內 + 8 分
13
If ((CircleX - X) ^ 2 + (CircleY - Y) ^ 2) <= 200 ^ 2 Then Label2 = Label2 + 1 ' 又在範圍 200 內 多加一分 = 9 分
14
If ((CircleX - X) ^ 2 + (CircleY - Y) ^ 2) <= 100 ^ 2 Then Label2 = Label2 + 1 ' 又在範圍 100 內 多加一分 = 10 分
15
Cls ' 只給一次打中或沒打中的機會 16
End Sub
09 10Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)11 ' 數學公式: (H-X)^2 + (K-Y)^2 <= R^2 等於點的位置在 半徑 R 範圍裡面12 If ((CircleX - X) ^ 2 + (CircleY - Y) ^ 2) <= 300 ^ 2 Then Label2 = Label2 + 8 ' 在範圍 300 內 + 8 分13 If ((CircleX - X) ^ 2 + (CircleY - Y) ^ 2) <= 200 ^ 2 Then Label2 = Label2 + 1 ' 又在範圍 200 內 多加一分 = 9 分14 If ((CircleX' 關閉倒數計時26
程式碼說明Private Sub Timer1_Timer()
19
Label1.Caption = Val(Label1) - 1
20
If Label1.Caption = 0 Then
21
Cls
22
CircleX = -9999999 ' 防止遊戲結束後點位置會加分
23
CircleY = -9999999 ' 防止遊戲結束後點位置會加分
24
MsgBox " 時間到! ", , " 遊戲結束 "
25
Timer1.Enabled = False ' 關閉倒數計時
26
Timer2.Enabled = False ' 關閉標靶
27
Command1.Enabled = True ' 重新開始遊戲
28
End If
29
End Sub
程式碼說明Private Sub Timer2_Timer()
32
Cls ' 清空畫面
33
Me.Scale (0, 5000)-(5000, 0)
34
CircleX = 300 + Int(Rnd * 3001)
35
CircleY = 500 + Int(Rnd * 3001)
36
37
Circle (CircleX, CircleY), 100
38
Circle (CircleX, CircleY), 200
39
Circle (CircleX, CircleY), 300
40
End Sub
上課心得
謝謝老師用心的教導,雖然這個遊戲看似平凡但我想這是我這學期學到最有成就感的一科 !