[英]Scoring my Dice Rolls using c# and Unity
Just trying wanting to be able to score my dice rolls following a rule set. 只是想希望能够按照规则集为骰子得分。 The rules range from making a single 1 rolled worth 100 points and three 1's worth 400, straight flush worth some points and 6x1's worth 8000. 规则的范围包括单注1掷出100分,三注1掷出400分,同花顺赢得一些分,6x1掷出8000分。
Here is the code. 这是代码。
I don't know how to make the code calculate the scores individually 我不知道如何使代码单独计算分数
int[] rollDice(int numDice)
{
int[] diceRolls = new int[6];
//int[] diceRolls = null;
for (int i = 0; i < NumDice; i++)
{
diceRolls[i] = rollSingleDie(6);
}
return diceRolls;
}
//Score the dice rolls in the array
int scoreDiceRolls(int[] rolls)
{
int score = 0;
//TODO: Complete the scoring logic
// for (int i = 0; i < NumDice; i++)
// {
// if (rolls[i] == 2 && 4)
// {
// score += 10;
// }
// }
// if (rolls[1] == 2)
// {
// score += 100;
// }
//SIX ONES RULE ////////////////////////////////////////////////////// NEED HELP HERE.
if (rolls[0] == 1)
{
if (rolls[1] == 1)
{
if (rolls[2] == 1)
{
if (rolls[3] == 1)
{
if (rolls[4] == 1)
{
if (rolls[5] == 1)
{
score += 8000;
}
}
}
}
}
}
// ROLL A ONE RULE = 100 points
for (int i = 0; i < NumSides; i++)
{
if (rolls[i] == 1)
{
score += 100;
}
} }
// int intToCheck = 1;
//foreach (int one in rolls)
//{
// if (x.Equals(1))
// {
// score += 10;
//
// }
//}
// if (rolls[)
//for (int i = 0; i < 6; i++)
//{
// if (rolls[i] == 1)
// {
// score += 10;
// }
//}
return score;
}
Note that when aggregating data in arrays (or any other enumerable) there are a number of helpful functions in System.Linq.Enumerable
请注意,在数组(或任何其他可枚举的)中聚合数据时, System.Linq.Enumerable
中有许多有用的功能
if(rolls
.Take(6) // Just to make sure we get six results
.All(r => r == 1)) // compare each result to 1
score += 8000;
Ok, bit of a messy question, but if you are looking for the number of times certain values are recieved I would do the following: 好的,有点麻烦,但是,如果您要查找获得某些值的次数,则可以执行以下操作:
int[] DiceRolls(int noOfRolls, int noOfSides)
{
int[] results = new int[noOfSides];
for (int i = 0; i < noOfRolls; i++)
{
results[rollSingleDie(noOfSides)]++;
}
return results;
}
This would allow you to check the number of times a certain value has been rolled. 这将允许您检查某个值被滚动的次数。
Edit: Just to clarify - for 6 1s you would need to do: 编辑:只是为了澄清-对于6 1s,您需要执行以下操作:
int[] rolls = DiceRolls(6, 6);
if (rolls[0] == 6)
{
score += 8000;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.