Yahtzee 3种! VB

时间:2014-04-30 19:43:48

标签: vb.net

我正在为一个学校的VB课程介绍yahtzee游戏。我已经完成了大部分计划,而且只有几套。但是,现在,我仍然坚持使用这三种套装,而且是四种套装。现在我正在处理我的3oak套装。

rdb3OAK - 一个无线电按钮,用户将检查他们是否打算将骰子放入3种

randnum1-5 - 五个骰子值中的每一个

lbl3OAK - 为其中3种奖励积分的标签将显示在

这是我的代码:

        '3 of a kind
        If rdb3OAK.Checked = True And randnum1 = randnum2 = randnum3 Then
            lbl3OAK.Text = randnum1 + randnum2 + randnum3 + randnum4 + randnum5
            rdb3OAK.Enabled = False
        End If
        If rdb3OAK.Checked = True And randnum1 = randnum2 = randnum4 Then
            lbl3OAK.Text = randnum1 + randnum2 + randnum3 + randnum4 + randnum5
            rdb3OAK.Enabled = False
        End If
        If rdb3OAK.Checked = True And randnum1 = randnum2 = randnum5 Then
            lbl3OAK.Text = randnum1 + randnum2 + randnum3 + randnum4 + randnum5
            rdb3OAK.Enabled = False
        End If
        If rdb3OAK.Checked = True And randnum1 = randnum3 = randnum4 Then
            lbl3OAK.Text = randnum1 + randnum2 + randnum3 + randnum4 + randnum5
            rdb3OAK.Enabled = False
        End If
        If rdb3OAK.Checked = True And randnum1 = randnum3 = randnum5 Then
            lbl3OAK.Text = randnum1 + randnum2 + randnum3 + randnum4 + randnum5
            rdb3OAK.Enabled = False
        End If
        If rdb3OAK.Checked = True And randnum1 = randnum4 = randnum5 Then
            lbl3OAK.Text = randnum1 + randnum2 + randnum3 + randnum4 + randnum5
            rdb3OAK.Enabled = False
        End If
        If rdb3OAK.Checked = True And randnum2 = randnum3 = randnum4 Then
            lbl3OAK.Text = randnum1 + randnum2 + randnum3 + randnum4 + randnum5
            rdb3OAK.Enabled = False
        End If
        If rdb3OAK.Checked = True And randnum2 = randnum3 = randnum5 Then
            lbl3OAK.Text = randnum1 + randnum2 + randnum3 + randnum4 + randnum5
            rdb3OAK.Enabled = False
        End If
        If rdb3OAK.Checked = True And randnum2 = randnum4 = randnum5 Then
            lbl3OAK.Text = randnum1 + randnum2 + randnum3 + randnum4 + randnum5
            rdb3OAK.Enabled = False
        End If
        If rdb3OAK.Checked = True And randnum3 = randnum4 = randnum5 Then
            lbl3OAK.Text = randnum1 + randnum2 + randnum3 + randnum4 + randnum5
            rdb3OAK.Enabled = False
        End If

对于相同数字的三个骰子的每个可能组合,都有一个if语句。在理论上这是有效的,但在实践中却没有。我根本没有收到任何错误,所以我不知道出了什么问题。

我是编程新手,所以要善待我!

任何提供的帮助都将不胜感激!

1 个答案:

答案 0 :(得分:1)

不幸的是,你无法做到" a = b = c"像那样。你需要做" a = b和b = c"。例如,更改此:

If rdb3OAK.Checked = True And randnum1 = randnum2 = randnum3 Then

对此:

If rdb3OAK.Checked = True And randnum1 = randnum2 And randnum2 = randnum3 Then

我在VB上有点生疏,所以你可能还需要使用" =="而不是" ="。 (在某些语言中," ="是作业," =="是比较。)