我正在制作一个2次骰子游戏,滚动100次并给出游戏统计数据并且它有效。问题在于,当模具1可能像68而模具2可能是32(模具1:68,骰子2:32)时,两个模具的总数为50。我怎么能根据我的代码来实现呢?
int[] Dice1 = new int[7];
int[] Dice2 = new int[7];
Random x = new Random();
for (int throw = 1; throw <= 50; throw++)
{
Dice1[x.Next(1, 7)]++;
Dice2[x.Next(1, 7)]++;
}
Console.WriteLine("Side | times");//How many times sides 1-6 appear.
for (int side = 1; side < Dice1.Length; side++)
{
Console.Write(" " + side + " ");
Console.WriteLine(Dice1[side] + Dice2[side]);
}
int total = Dice1.Sum() + Dice2.Sum();
Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~");
Console.WriteLine("total of 1. Dice: " + Dice1.Sum());
Console.WriteLine("total of 2. Dice: " + Dice2.Sum());
Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~");
Console.Write("Total Sum: ");
Console.WriteLine(total);
输出:
http://oi60.tinypic.com/140vzid.jpg
如果有人知道如何让这个工作,请回答,非常感谢。
答案 0 :(得分:2)
目前你正在滚动2个骰子50次(总共100个骰子)。听起来你想要执行100个模具辊,其中每个辊随机选择模具进行滚动。在这种情况下,只需将循环更改为循环100次,而不是50循环,而不是滚动两者,选择一个滚动:
for (int throw = 1; throw <= 100; throw++)
{
if(x.Next(0,2) == 0)
Dice1[x.Next(1, 7)]++;
else
Dice2[x.Next(1, 7)]++;
}