在确定骰子游戏计分逻辑时需要帮助 [英] Need help on figuring out dice game scoring logic

查看:177
本文介绍了在确定骰子游戏计分逻辑时需要帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我们基于游戏Farkle在VB.net中创建一个游戏.基本上,您掷出一定数量的骰子,具体取决于您保留的得分.我们有八个骰子.这是一个例子,假设您掷出3个"3",并且想要对它们进行打分(三个).我们想一起检查所有骰子,看看是否确实有三个3.我们已经弄清了这两种,但是我们却无法弄清这三种.

So, we are creating a game in VB.net based off the game, Farkle. Basically, you roll an amount of dice and depending on what you keep is your score. We have eight dice. Here's an example, say you roll 3 "3"s and you want to score them, a three of a kind. We want to check all the dice together to see if we do have three 3's. We have figured out the two of a kind, but the three of a kind we cannot.

For l = 0 To 5
            For o = 1 To 6
                For q = 2 To 7
                    If (DieScore(l) = DieScore(o) And DieScore(l) = DieScore(q)) Then
                        PlayerScore = 200 + PlayerScore
                    End If
                Next
            Next
        Next

这是我们在骰子上检查三个骰子的方法.如果是真的,我们将分数加200. DieScore(x)是指骰子.我们要去哪里错了?

This is our checking for three of a kind on the dice. If it is true we add 200 to the score. The DieScore(x) refer to the dice. Where are we going wrong?

推荐答案

您实际上只需要循环并计算数组中出现的点数(点)的次数.

You really just need to loop and count how many times that number of pips (spots) appears in the array.

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

并非没有,但是使用调试器很容易发现这些逻辑问题.另外,您还将学习有关代码如何执行的 lot .

Not for nothing, but these kinds of logic issues are easy to find using the Debugger. Plus, you will learn a lot about how code executes.

这篇关于在确定骰子游戏计分逻辑时需要帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆