我正在尝试在Visual Basic 2010中创建匹配游戏,并检查所选卡片实际上是否匹配我想将firstchoice.image的值与secondchoice.image进行比较。
我遇到的问题是,在比较中,anything.image的值返回为System.Drawing.Bitmap
,因此比较总是返回true。
现在的比较代码是:
If FirstI Is My.Resources.circle Then
TempOne = 1
ElseIf FirstI Is My.Resources.crescent Then
TempOne = 2
ElseIf FirstI Is My.Resources.pentagram Then
TempOne = 3
ElseIf FirstI Is My.Resources.square Then
TempOne = 4
ElseIf FirstI Is My.Resources.triangle Then
TempOne = 5
ElseIf FirstI Is My.Resources.yinyang Then
TempOne = 6
End If
If SecondI Is My.Resources.circle Then
TempOne = 1
ElseIf SecondI Is My.Resources.crescent Then
TempOne = 2
ElseIf SecondI Is My.Resources.pentagram Then
TempOne = 3
ElseIf SecondI Is My.Resources.square Then
TempOne = 4
ElseIf SecondI Is My.Resources.triangle Then
TempOne = 5
ElseIf SecondI Is My.Resources.yinyang Then
TempOne = 6
End If
Debug.WriteLine(FirstI)
Debug.WriteLine(SecondI)
If TempOne = TempTwo Then
Return True
Else
Return False
End If
FirstI和SecondI被声明为
Private FirstI As Image
Private SecondI As Image
并填充从图像数组中提取的数据。
Private Cards() As Image = {My.Resources.circle, My.Resources.crescent, My.Resources.pentagram, My.Resources.square, My.Resources.triangle, My.Resources.yinyang, My.Resources.circle, My.Resources.crescent, My.Resources.pentagram, My.Resources.square, My.Resources.triangle, My.Resources.yinyang}
答案 0 :(得分:1)
如果我是你,我不会尝试直接比较对象/值,我只想比较状态。保持FirstIIndex和SecondIIndex(作为整数),它们是从0到Cards.Length的索引整数。设置该值时,将图像设置为卡片(FirstIIndex)。如果你想看看它们是否设置为相同的东西,只需检查FirstIIndex = SecondIndex。