嘿所以我正在尝试创建这个小机器人..但是我从朋友那里得到了这个代码,它是一个小的5x5瓷砖,我只能用这个选择一个瓷砖,它只会使用一个瓷砖。我希望能够选择多个瓷砖,然后机器人也将使用已注册的多个瓷砖。
Tiles代码是
Public Class Tiles
Private _activeTile As Integer = 0
Public ReadOnly Property activeTile As Integer
Get
Return _activeTile
End Get
End Property
Private Sub PictureBox_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click, PictureBox2.Click, PictureBox3.Click, PictureBox4.Click, PictureBox5.Click, PictureBox6.Click, PictureBox7.Click, PictureBox8.Click, PictureBox9.Click, PictureBox10.Click, PictureBox11.Click, PictureBox12.Click, PictureBox13.Click, PictureBox14.Click, PictureBox15.Click, PictureBox16.Click, PictureBox17.Click, PictureBox18.Click, PictureBox19.Click, PictureBox20.Click, PictureBox21.Click, PictureBox22.Click, PictureBox23.Click, PictureBox24.Click, PictureBox25.Click
Dim p As PictureBox = TryCast(sender, PictureBox)
Dim id As Integer = CInt(p.Name.Split("x")(1))
If p.BorderStyle = Windows.Forms.BorderStyle.Fixed3D Then
p.BorderStyle = Windows.Forms.BorderStyle.None
p.BackColor = System.Drawing.Color.FromArgb(&HDD, &HDD, &HDD)
_activeTile = 0
Else
resetActiveTile()
p.BorderStyle = Windows.Forms.BorderStyle.Fixed3D
p.BackColor = System.Drawing.Color.FromArgb(&HA9, &HA9, &HA9)
_activeTile = id
End If
End Sub
Public Sub resetActiveTile()
For Each c As Control In Me.Controls
If c.Name.StartsWith("Pic") Then
Dim p As PictureBox = TryCast(c, PictureBox)
Dim id As Integer = CInt(p.Name.Split("x")(1))
p.BorderStyle = Windows.Forms.BorderStyle.None
p.BackColor = System.Drawing.Color.FromArgb(&HDD, &HDD, &HDD)
_activeTile = 0
End If
Next
End Sub
Private Sub Tiles_Load(sender As Object, e As EventArgs) Handles MyBase.Load
PictureBox1.BorderStyle = Windows.Forms.BorderStyle.Fixed3D
PictureBox1.BackColor = System.Drawing.Color.FromArgb(&HA9, &HA9, &HA9)
_activeTile = 1
End Sub
结束班
这是使用活动图块的功能
Private Sub guess()
Try
If Tiles1.activeTile = 0 Then
BackgroundWorker1.CancelAsync()
MsgBox("Please select a tile!")
Else
s.Guess(currGame, Tiles1.activeTile)
End If
Catch ex As Exception
log(ex.ToString)
End Try
End Sub
非常感谢! :)