Vb.net 需要了解骰子游戏得分逻辑的帮助吗

Vb.net 需要了解骰子游戏得分逻辑的帮助吗,vb.net,logic,dice,Vb.net,Logic,Dice,因此,我们正在VB.net中基于游戏Farkle创建一个游戏。基本上,你掷了一定数量的骰子,根据你的分数而定。我们有八个骰子。这里有一个例子,假设你掷3“3”,你想得分,一个3分。我们想一起检查所有的骰子,看看我们是否有三个3。我们已经找到了两个同类,但我们无法找到三个同类 用于l=0到5 对于o=1到6 对于q=2到7 如果(DieScore(l)=DieScore(o)和DieScore(l)=DieScore(q)),那么 PlayerScore=200+PlayerScore 如果结束

因此,我们正在VB.net中基于游戏Farkle创建一个游戏。基本上,你掷了一定数量的骰子,根据你的分数而定。我们有八个骰子。这里有一个例子,假设你掷3“3”,你想得分,一个3分。我们想一起检查所有的骰子,看看我们是否有三个3。我们已经找到了两个同类,但我们无法找到三个同类

用于l=0到5
对于o=1到6
对于q=2到7
如果(DieScore(l)=DieScore(o)和DieScore(l)=DieScore(q)),那么
PlayerScore=200+PlayerScore
如果结束
下一个
下一个
下一个

这是我们检查骰子上的三个同类。如果这是真的,我们在分数上加200。骰子分数(x)指的是骰子。哪里出了问题?

您只需循环并计算阵列中出现的点数(点)的多少倍

Dim count As Integer = 0

For pips As Integer = 1 To 6
    count = 0                      ' reset count for each Pip iteration
    For n As Integer = 0 To DieScore.Length - 1

        ' If operator version:
        count += If(DieScore(n) = pips, 1, 0)

        ' If Statement version:
        'If DieScore(n) = pips Then
        '    count += 1
        'End If
    Next

    ' scoring
    Select Case count
        Case 2    ' pair
            playerscore += 50
        Case 3    ' trips
            playerscore += 200
            If pips = 6 Then
                playerscore += 25    ' extra bonus for 666 (example)
            End If
        Case 4    ' quads
            playerscore += 350
        ' etc
    End Select
Next

并非毫无意义,但是使用调试器很容易找到这些类型的逻辑问题。此外,您还将了解到许多关于代码执行方式的知识。

您只需循环并计算数组中出现的点数(点)的次数

Dim count As Integer = 0

For pips As Integer = 1 To 6
    count = 0                      ' reset count for each Pip iteration
    For n As Integer = 0 To DieScore.Length - 1

        ' If operator version:
        count += If(DieScore(n) = pips, 1, 0)

        ' If Statement version:
        'If DieScore(n) = pips Then
        '    count += 1
        'End If
    Next

    ' scoring
    Select Case count
        Case 2    ' pair
            playerscore += 50
        Case 3    ' trips
            playerscore += 200
            If pips = 6 Then
                playerscore += 25    ' extra bonus for 666 (example)
            End If
        Case 4    ' quads
            playerscore += 350
        ' etc
    End Select
Next

并非毫无意义,但是使用调试器很容易找到这些类型的逻辑问题。此外,您还将了解到许多关于代码执行方式的知识。

您只需循环并计算数组中出现的点数(点)的次数

Dim count As Integer = 0

For pips As Integer = 1 To 6
    count = 0                      ' reset count for each Pip iteration
    For n As Integer = 0 To DieScore.Length - 1

        ' If operator version:
        count += If(DieScore(n) = pips, 1, 0)

        ' If Statement version:
        'If DieScore(n) = pips Then
        '    count += 1
        'End If
    Next

    ' scoring
    Select Case count
        Case 2    ' pair
            playerscore += 50
        Case 3    ' trips
            playerscore += 200
            If pips = 6 Then
                playerscore += 25    ' extra bonus for 666 (example)
            End If
        Case 4    ' quads
            playerscore += 350
        ' etc
    End Select
Next

并非毫无意义,但是使用调试器很容易找到这些类型的逻辑问题。此外,您还将了解到许多关于代码执行方式的知识。

您只需循环并计算数组中出现的点数(点)的次数

Dim count As Integer = 0

For pips As Integer = 1 To 6
    count = 0                      ' reset count for each Pip iteration
    For n As Integer = 0 To DieScore.Length - 1

        ' If operator version:
        count += If(DieScore(n) = pips, 1, 0)

        ' If Statement version:
        'If DieScore(n) = pips Then
        '    count += 1
        'End If
    Next

    ' scoring
    Select Case count
        Case 2    ' pair
            playerscore += 50
        Case 3    ' trips
            playerscore += 200
            If pips = 6 Then
                playerscore += 25    ' extra bonus for 666 (example)
            End If
        Case 4    ' quads
            playerscore += 350
        ' etc
    End Select
Next

并非毫无意义,但是使用调试器很容易找到这些类型的逻辑问题。此外,您还将了解到许多有关代码执行方式的知识。

对于初学者,请学习使用不同的、比
l
o
更具描述性的变量名,它们很容易与
1
0
混淆。一些著名的bug是由这样的操作引起的

你们可以做的一件事就是简单地计算一卷骰子中有多少个点或点子,并将其存储在一个数组中

' index 0 = 1 spot, 5 = 6 spots.
Dim pipsCount(6) as Integer 

' This counts the number of dice for each possible "pips"
For dieIndex as Integer = 0 To DieScore.Length - 1
    ' Increment (the -1 is because index starts at 0)
    pipsCount(DieScore(dieIndex)-1) += 1
Next
现在你已经有了一定点数的骰子,你可以用它做很多不同的事情

' You can easily find out now how many sixes were thrown:
Dim numberOfSixes As Integer = pipsCount(6-1) 

' Or score pairs, trips, quads, ...
For pipsIndex As Integer = 0 To 5
    Select Case pipsCount(pipsIndex)
        Case 2
            PlayerScore += 50
        Case 3
            PlayerScore += 200
        ' ... etc
    End Select
Next

' Or count the length of a straight 
Dim straightLength As Integer = If(pipsCount(0) > 0, 1, 0)
Dim longestStraight As Integer = straightLength 
For pipsIndex As Integer = 1 To 5
    If pipsCount(pipsIndex) > 0 Then
        straightLength += 1
    Else ' straight ended
        If straightLength > longestStraight Then
            longestStraight = straightLength 
        End If
        straightLength = 0
    End If
Next

对于初学者,请学习使用不同的、比
l
o
更具描述性的变量名,它们很容易与
1
0
混淆。一些著名的bug是由这样的操作引起的

你们可以做的一件事就是简单地计算一卷骰子中有多少个点或点子,并将其存储在一个数组中

' index 0 = 1 spot, 5 = 6 spots.
Dim pipsCount(6) as Integer 

' This counts the number of dice for each possible "pips"
For dieIndex as Integer = 0 To DieScore.Length - 1
    ' Increment (the -1 is because index starts at 0)
    pipsCount(DieScore(dieIndex)-1) += 1
Next
现在你已经有了一定点数的骰子,你可以用它做很多不同的事情

' You can easily find out now how many sixes were thrown:
Dim numberOfSixes As Integer = pipsCount(6-1) 

' Or score pairs, trips, quads, ...
For pipsIndex As Integer = 0 To 5
    Select Case pipsCount(pipsIndex)
        Case 2
            PlayerScore += 50
        Case 3
            PlayerScore += 200
        ' ... etc
    End Select
Next

' Or count the length of a straight 
Dim straightLength As Integer = If(pipsCount(0) > 0, 1, 0)
Dim longestStraight As Integer = straightLength 
For pipsIndex As Integer = 1 To 5
    If pipsCount(pipsIndex) > 0 Then
        straightLength += 1
    Else ' straight ended
        If straightLength > longestStraight Then
            longestStraight = straightLength 
        End If
        straightLength = 0
    End If
Next

对于初学者,请学习使用不同的、比
l
o
更具描述性的变量名,它们很容易与
1
0
混淆。一些著名的bug是由这样的操作引起的

你们可以做的一件事就是简单地计算一卷骰子中有多少个点或点子,并将其存储在一个数组中

' index 0 = 1 spot, 5 = 6 spots.
Dim pipsCount(6) as Integer 

' This counts the number of dice for each possible "pips"
For dieIndex as Integer = 0 To DieScore.Length - 1
    ' Increment (the -1 is because index starts at 0)
    pipsCount(DieScore(dieIndex)-1) += 1
Next
现在你已经有了一定点数的骰子,你可以用它做很多不同的事情

' You can easily find out now how many sixes were thrown:
Dim numberOfSixes As Integer = pipsCount(6-1) 

' Or score pairs, trips, quads, ...
For pipsIndex As Integer = 0 To 5
    Select Case pipsCount(pipsIndex)
        Case 2
            PlayerScore += 50
        Case 3
            PlayerScore += 200
        ' ... etc
    End Select
Next

' Or count the length of a straight 
Dim straightLength As Integer = If(pipsCount(0) > 0, 1, 0)
Dim longestStraight As Integer = straightLength 
For pipsIndex As Integer = 1 To 5
    If pipsCount(pipsIndex) > 0 Then
        straightLength += 1
    Else ' straight ended
        If straightLength > longestStraight Then
            longestStraight = straightLength 
        End If
        straightLength = 0
    End If
Next

对于初学者,请学习使用不同的、比
l
o
更具描述性的变量名,它们很容易与
1
0
混淆。一些著名的bug是由这样的操作引起的

你们可以做的一件事就是简单地计算一卷骰子中有多少个点或点子,并将其存储在一个数组中

' index 0 = 1 spot, 5 = 6 spots.
Dim pipsCount(6) as Integer 

' This counts the number of dice for each possible "pips"
For dieIndex as Integer = 0 To DieScore.Length - 1
    ' Increment (the -1 is because index starts at 0)
    pipsCount(DieScore(dieIndex)-1) += 1
Next
现在你已经有了一定点数的骰子,你可以用它做很多不同的事情

' You can easily find out now how many sixes were thrown:
Dim numberOfSixes As Integer = pipsCount(6-1) 

' Or score pairs, trips, quads, ...
For pipsIndex As Integer = 0 To 5
    Select Case pipsCount(pipsIndex)
        Case 2
            PlayerScore += 50
        Case 3
            PlayerScore += 200
        ' ... etc
    End Select
Next

' Or count the length of a straight 
Dim straightLength As Integer = If(pipsCount(0) > 0, 1, 0)
Dim longestStraight As Integer = straightLength 
For pipsIndex As Integer = 1 To 5
    If pipsCount(pipsIndex) > 0 Then
        straightLength += 1
    Else ' straight ended
        If straightLength > longestStraight Then
            longestStraight = straightLength 
        End If
        straightLength = 0
    End If
Next

你似乎已经把你的VB.NET代码中的C语句或C++语句混合了。不要忘记(和)而不是(和)数组索引。@布莱克伍德,我希望我能得到它们。你似乎已经把你的VB.NET代码中的C语句或C++语句混合了。不要忘记(和)而不是(和)数组索引。@布莱克伍德,我希望我能得到它们。你似乎已经把你的VB.NET代码中的C语句或C++语句混合了。不要忘记(和)而不是(和)数组索引。@布莱克伍德,我希望我能得到它们。你似乎已经把你的VB.NET代码中的C语句或C++语句混合了。不要忘记(和)而不是(和)数组索引。@布莱克伍德,我希望我能得到它们。法克尔应该只有6个骰子,而不是8个。法克尔应该只有6个骰子,而不是8个。法克尔应该只有6个骰子,而不是8个。法克尔应该只有6个骰子,而不是8个。