[.NET] 捉小偷程式碼更改
請輸入專案類型(網站專案或者應用程式專案):
vb2008-捉小偷
想請問一下,如果我要把圖片變成二個,一個是點到小偷會加分,一個是點到警察會扣分
那麼程式碼該如何改?
以下是程式碼部分
謝謝大大的回答了!
Imports System.Text 'Encode會用到
Public Class MainForm
#Region "Variables Declaration"
'儲存狀態用變數
Public UserName As String '使用者名稱
'遊戲用變數
Private createTime As Integer '要產生地鼠的剩餘時間
Private userColor As Color '玩家和按鈕顏色
Private score As Integer '玩家分數
#End Region
#Region "Game Functions"
Private Delegate Sub DelegateInitialize()
'初始化遊戲狀態
Public Sub Initialize()
'初始化
score = 0
Label_UserScoreNum.Text = "0"
'將所有洞清空
Dim i As Integer
For i = 0 To Panel_GameArea.Controls.Count - 1
If Panel_GameArea.Controls(i).Name.Substring(0, 4) = "Hole" Then
Dim tmpPic As PictureBox = Panel_GameArea.Controls(i)
tmpPic.Image = ImageList_Rat.Images.Item(0)
tmpPic.Tag = 0
End If
Next
End Sub
'開始計時
Private Delegate Sub DelegateStartTimer()
Private Sub StartTimer()
Label_Time.Text = "20"
Timer_Game.Enabled = True
Timer_Thief.Enabled = True
End Sub
'停止計時
Private Sub StopTimer()
Label_Time.Text = "-"
Timer_Game.Enabled = False
'將所有洞清空
Dim i As Integer
For i = 0 To Panel_GameArea.Controls.Count - 1
If Panel_GameArea.Controls(i).Name.Substring(0, 4) = "Hole" Then
Dim tmpPic As PictureBox = Panel_GameArea.Controls(i)
tmpPic.Image = ImageList_Rat.Images.Item(0)
tmpPic.Tag = 0
End If
Next
End Sub
'每秒遊戲計時以及隨機產生地鼠
Private Sub Timer_Game_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer_Game.Tick
UpdateRatLiveTime() '更新每個地鼠存活時間
CreateRandomRat() '邀請方產生地鼠
CheckGame() '檢查遊戲是否結束
End Sub
Private Sub UpdateRatLiveTime()
'每秒遞減每個地鼠的剩餘時間,若為0則變為空洞
If Integer.Parse(Label_Time.Text) <> 0 Then
Dim i As Integer
For i = 0 To Panel_GameArea.Controls.Count - 1
If Panel_GameArea.Controls(i).Name.Substring(0, 4) = "Hole"
Then
Dim tmpPic As PictureBox = Panel_GameArea.Controls(i)
If tmpPic.Tag <> 0 Then
tmpPic.Tag -= 1
Else
tmpPic.Image = ImageList_Rat.Images.Item(0)
tmpPic.Refresh()
End If
End If
Next
Label_Time.Text = (Integer.Parse(Label_Time.Text) - 1).ToString
ElseIf Integer.Parse(Label_Time.Text) = 0 Then
StopTimer()
End If
End Sub
'受邀者產生地鼠
Private Sub CreateRat(ByVal CreateName As String)
Dim i As Integer
For i = 0 To Panel_GameArea.Controls.Count - 1
If Panel_GameArea.Controls(i).Name = CreateName Then
Dim tmpPic As PictureBox = Panel_GameArea.Controls(i)
tmpPic.Image = My.Resources.peace
tmpPic.Refresh()
tmpPic.Tag = 3
ElseIf Panel_GameArea.Controls(i).Name = CreateName Then
Exit For
End If
Next
End Sub
Private Sub CreateRandomRat()
Dim index As Integer
If createTime = 0 Then
Randomize()
createTime = Rnd() * 5
Else
createTime -= 1
End If
If createTime <> 0 Then
While True
Randomize()
index = Rnd() * 8
Dim tmpPic As PictureBox = Panel_GameArea.Controls(index)
'假如是空洞,才產生地鼠
If tmpPic.Tag = 0 Then
tmpPic.Image = My.Resources.peace
tmpPic.Refresh()
tmpPic.Tag = 3
Exit While
End If
End While
End If
End Sub
'檢查遊戲是否結束
Private Sub CheckGame()
If Integer.Parse(Label_Time.Text) = 0 Then
StopTimer()
MsgBox("您的成績:" + score.ToString)
End If
End Sub
'當玩家打中地鼠時事件
Public Sub ratClick(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Hole1.Click, Hole2.Click, _
Hole3.Click, Hole4.Click, Hole5.Click, Hole6.Click, Hole7.Click,
Hole8.Click, Hole9.Click
Dim tmpPic As PictureBox = sender
'以地鼠的時間標籤來判斷 (也可以用圖片判斷)
If tmpPic.Tag <> 0 Then
'加分
score += 50
Label_UserScoreNum.Text = score.ToString
'清空地洞
tmpPic.Tag = 0
tmpPic.Image = ImageList_Rat.Images.Item(0)
End If
End Sub
'遊戲結束,回覆之前狀態
Private Sub EndGame()
score = 0
Label_UserScoreNum.Text = "0"
StopTimer()
End Sub
#End Region
'當遊戲視窗載入便開始遊戲
Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Initialize()
StartTimer()
End Sub
Private Sub Panel_GameArea_Paint(ByVal sender As System.Object, ByVal e
As System.Windows.Forms.PaintEventArgs) Handles Panel_GameArea.Paint
End Sub
Private Sub GameBox_Enter(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles GameBox.Enter
End Sub
End Class
謝謝
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.24.52.131
※ 文章網址: https://www.ptt.cc/bbs/Visual_Basic/M.1464070917.A.69A.html
→
05/24 14:41, , 1F
05/24 14:41, 1F
??不好意思,不了解呢?
→
05/24 17:19, , 2F
05/24 17:19, 2F
→
05/24 22:28, , 3F
05/24 22:28, 3F
推
05/25 08:07, , 4F
05/25 08:07, 4F
謝謝兩位大大的回答!
※ 編輯: koalaflsh (59.115.103.179), 05/25/2016 13:50:50
討論串 (同標題文章)
完整討論串 (本文為第 1 之 2 篇):
1
4
Visual_Basic 近期熱門文章
PTT數位生活區 即時熱門文章