If 语句和图片框值问题
If statements and picture box values issue
我正在尝试创建一个 snap 游戏,但是在检查图片框是否包含正确的图像时,它根本不起作用,我对此做了一些研究并实现了这些想法.它不会抛出任何类型的错误,但我只是没有在应该的时候收到增加的价值。请查看这段代码,如果您知道我哪里出错了,请告诉我。
尝试 1:
Dim BirdPics() As Image = {My.Resources.Image_1}
If tbxAnimal_Group.Text = "Birds" And BirdPics.Contains(pbxPicture.Image) Then
CurrentPoints += 1
lblScore.Text = "Score:" & CurrentPoints
End If
尝试 2
Dim BirdPics() As Image = {My.Resources.Image_1}
If tbxAnimal_Group.Text = "Birds" And pbxPicture Is BirdPics Then
CurrentPoints += 1
lblScore.Text = "Score:" & CurrentPoints
End If
不要使用"BirdPics.Contains";它不是那样工作的。
无法对图像进行简单比较。
IF ThisImage = ThatImage THEN ' 不一定有效,即使它可以编译。
创建结构或class并将它们存储在列表中。
Structure gameObjects
BirdPic as Image
BirdPicName as string
Position as Point
End Structure
DIM GamePictures(0) AS gameObjects
SUB Main()
' Create a new object
DIM newObj as New gameObjects
With newObj
.BirdPic = Image.FromFile("pics/bluejay.jpg")
.BirdPicName = "BlueJay"
.Position = new point(10, 20)
End With
AddObject(newObj)
for index = 0 to gamepictures.count - 1
If tbxAnimal_Group.Text = "Birds" AND GamePictures(index).BirdPicName = "BlueJay" THEN
' Do Something
End If
next
END SUB
Public Sub AddObject(obj as GameObjects)
DIM thisObjIndex as integer = GamePictures.Count
ReDim preserve GamePictures(thisObjIndex + 1)
GamePictures(thisObjIndex) = obj
End Sub
我正在尝试创建一个 snap 游戏,但是在检查图片框是否包含正确的图像时,它根本不起作用,我对此做了一些研究并实现了这些想法.它不会抛出任何类型的错误,但我只是没有在应该的时候收到增加的价值。请查看这段代码,如果您知道我哪里出错了,请告诉我。
尝试 1:
Dim BirdPics() As Image = {My.Resources.Image_1}
If tbxAnimal_Group.Text = "Birds" And BirdPics.Contains(pbxPicture.Image) Then
CurrentPoints += 1
lblScore.Text = "Score:" & CurrentPoints
End If
尝试 2
Dim BirdPics() As Image = {My.Resources.Image_1}
If tbxAnimal_Group.Text = "Birds" And pbxPicture Is BirdPics Then
CurrentPoints += 1
lblScore.Text = "Score:" & CurrentPoints
End If
不要使用"BirdPics.Contains";它不是那样工作的。
无法对图像进行简单比较。
IF ThisImage = ThatImage THEN ' 不一定有效,即使它可以编译。
创建结构或class并将它们存储在列表中。
Structure gameObjects
BirdPic as Image
BirdPicName as string
Position as Point
End Structure
DIM GamePictures(0) AS gameObjects
SUB Main()
' Create a new object
DIM newObj as New gameObjects
With newObj
.BirdPic = Image.FromFile("pics/bluejay.jpg")
.BirdPicName = "BlueJay"
.Position = new point(10, 20)
End With
AddObject(newObj)
for index = 0 to gamepictures.count - 1
If tbxAnimal_Group.Text = "Birds" AND GamePictures(index).BirdPicName = "BlueJay" THEN
' Do Something
End If
next
END SUB
Public Sub AddObject(obj as GameObjects)
DIM thisObjIndex as integer = GamePictures.Count
ReDim preserve GamePictures(thisObjIndex + 1)
GamePictures(thisObjIndex) = obj
End Sub