【问题标题】:My array values are incorrect when loading them into a dialogue box Visual Basic 2010将它们加载到对话框 Visual Basic 2010 时,我的数组值不正确
【发布时间】:2013-03-19 04:17:19
【问题描述】:

我不确定我应该给这个主题起什么名字,但我会解释一下情况。

我有一个存储卡值的数组。现在我正在为我的游戏实现闪避和格挡卡,所以我决定制作一个新的对话框视觉基础。 在打开对话框之前,我的程序会检查被攻击的玩家手中(在数组中)是否有闪避或格挡卡,如果是,则打开对话框。

对话框打开后,它将我的模块化玩家回合变量“T”重新分配给玩家攻击的值,将其更改为该玩家回合。

然后我加载我的通用子

从那里我将所有被攻击玩家的卡片加载到复选框中。

问题从这里开始 加载卡片后,我查看我的摘要索引,即玩家卡片索引。玩家按预期保留他的牌,但不知何故,索引也会随机减去一张牌并添加一张随机牌。

例如

正确的卡片:

道奇 1

第 1 块

头顶 1

一巴掌

踢1

'附加功能

戳-1

万岁玛丽 1

比较卡片的代码:

If LunchMoneyMainForm.T = 0 Then
    For roll = 0 To 4
        Dim temp As IEnumerable(Of LunchMoneyMainForm.Group) = _
            From r In LunchMoneyMainForm.Player1HandGroup _
            Where r.QuantityInteger > 0 _
            Select r
        If temp IsNot Nothing AndAlso temp.Count > 0 Then
            Dim rolls As Integer = roll Mod 5
            Number = (temp(LunchMoneyMainForm.Rnd.Next(0, temp.Count)).ID)
            LunchMoneyMainForm.Player1HandGroup(Number).QuantityInteger -= 1
            CheckBoxArray(rolls).Text = LunchMoneyMainForm.Player1HandGroup(Number).CardNameString
            LunchMoneyMainForm.NumberArray(roll) = Number
        End If
    Next roll
    For roll = 0 To 4
        Number = LunchMoneyMainForm.NumberArray(roll)
        LunchMoneyMainForm.Player1HandGroup(Number).QuantityInteger += 1
    Next
End If

有没有更好的方法来做到这一点?

编辑:我注释掉了

'For roll = 0 To 4
'    Number = LunchMoneyMainForm.NumberArray(roll)
'    LunchMoneyMainForm.Player1HandGroup(Number).QuantityInteger += 1
'Next

我也拿出了LunchMoneyMainForm.Player1HandGroup(Number).QuantityInteger -= 1,但是 我仍然得到一个项目的 +1 和一个项目的 -1。

所以我的 Linq 函数中的某些东西正在这样做。

编辑: 我的球员卡汇总函数。

Private Sub PlayerHandToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PlayerHandToolStripMenuItem.Click
        For Me.intCount = 0 To 27

            CountHandCards += Player1HandGroup(intCount).QuantityInteger + Player1HandGroup(intCount).QuantityInteger2 + Player1HandGroup(intCount).QuantityInteger3 _
                + Player1HandGroup(intCount).QuantityInteger4 + Player1HandGroup(intCount).QuantityInteger5

            HandMsg = HandMsg & Player1HandGroup(intCount).CardNameString & ": " & Player1HandGroup(intCount).QuantityInteger & "            " & Player1HandGroup(intCount).QuantityInteger2 & _
              "            " & Player1HandGroup(intCount).QuantityInteger3 & "            " & Player1HandGroup(intCount).QuantityInteger4 & "            " & Player1HandGroup(intCount).QuantityInteger5 & Environment.NewLine
        Next intCount

        MessageBox.Show("Card Quantities in Hand:" & Environment.NewLine & HandMsg & Environment.NewLine & "Hand Total: " & CountHandCards.ToString)
        HandMsg = ""
        CountHandCards = 0
    End Sub

我知道摘要过程应该可以正常工作,因为在我加载 DodgeBlockCard 对话框之前不会显示错误的数据。

【问题讨论】:

  • 从你贴的有限代码很难判断,但是你在调用你贴的代码之前清除CheckBoxArray了吗?
  • 否,因为它被加载到 5 个复选框中。该部分的工作方式与预期相同。得到错误数字的是数量整数。
  • 您可以发布在您的示例中打印结果的代码吗?
  • 我坐下来沉思了一会,再次执行我的程序,发现负数的牌总是atker打出的牌,新牌总是atkers的新牌本来应该。发生的事情是我的程序的其余部分正在执行,并且由于我将回合临时更改为防御玩家以便他们可以放置闪避或阻挡卡,因此在攻击者库存中减去和添加卡的变量将改为在防御者库存。
  • 如何在对话框关闭之前暂停我的应用程序?

标签: vb.net linq random numbers


【解决方案1】:

回答“如何在对话框关闭之前暂停我的应用程序?”问题:

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
...
'Sleep for 1000 milliseconds
Sleep 1000

【讨论】:

  • 这会导致应用程序停止一段时间吗? PS 某种 DO 循环也可以工作吗?
  • 它将停止执行而不会用循环阻塞 CPU
  • 相反,我完成了播放按钮程序并以这种方式修复了它。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-02-29
  • 2012-05-21
  • 2020-04-03
  • 1970-01-01
  • 1970-01-01
  • 2012-05-07
  • 1970-01-01
相关资源
最近更新 更多