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
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?
For starters, please learn to use different, more descriptive variable names than
l
ando
, that are easily confused with1
and0
. Some famous bugs have been caused by doing things like that.One thing you can do is simply count how many dots or pips there are in a roll of the dice and store that in an array.
Now that you have the number of dice that landed headsup with a given number of pips, you can do a number of different things with that.
You really just need to loop and count how many times that number of pips (spots) appears in the array.
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.