[.NET] 捉小偷程式码更改

楼主: koalaflsh (刷子)   2016-05-24 14:21:55
请输入专案类型(网站专案或者应用程式专案):
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
谢谢
作者: MOONRAKER (㊣牛鹤鳗毛人)   2016-05-24 14:41:00
把tag改成两种程式你自己写的怎么会不了解 讲这样已经很多了好吗不然麻烦洽code_job板
作者: Marty (DNA探针)   2016-05-25 08:07:00
改Tag+1

Links booklink

Contact Us: admin [ a t ] ucptt.com