Re: [.NET] 捉小偷程式碼更改

作者: koalaflsh (刷子)   2016-05-25 13:49:23
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
Timer_elag.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
Dim tmpPic2 As PictureBox = Panel_GameArea.Controls(i)
tmpPic2.Image = My.Resources.elag
tmpPic2.Refresh()
tmpPic2.Tag = 3
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() * 4
Dim tmpPic As PictureBox = Panel_GameArea.Controls(index)
Dim tmpPic2 As PictureBox = Panel_GameArea.Controls(index)
'假如是空洞,才產生地鼠
If tmpPic.Tag = 0 Then
tmpPic.Image = My.Resources.peace
tmpPic.Refresh()
tmpPic.Tag = 1
Else : tmpPic2.Tag = 0
tmpPic2.Image = My.Resources.elag
tmpPic2.Refresh()
tmpPic2.Tag = 0
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
Dim tmpPic2 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)
ElseIf tmpPic2.Tag <> 0 Then
'加分
score -= 50
Label_UserScoreNum.Text = score.ToString
'清空地洞
tmpPic2.Tag = 0
tmpPic2.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
End Class
我自己改後,還是沒有辦法有這樣的效果,反而是只有小偷的圖片是加分的,是哪裡改錯
嗎?也謝謝之前的兩位大大的回答了!
作者: MOONRAKER (㊣牛鶴鰻毛人)   2016-05-25 14:18:00
改了tag當然別的地方也要改阿計分的地方要對應tag阿 你去游泳池會只脫上衣嗎

Links booklink

Contact Us: admin [ a t ] ucptt.com