예제 #1
0
    public int calculateDice(int totalDiceNum, int dic3, int dic6)
    {
        if ((dic3 + dic6) > totalDiceNum)
        {
            return(0);
        }


        int[] resD3Array    = new int[dice3Amount];
        int   _RollD3resSUM = 0;

        int[] resD6Array    = new int[dice6Amount];
        int   _RollD6resSUM = 0;

        for (int i = 0; i < dice3Amount; i++)
        {
            Dice tem = new Dice3();
            tem.Roll();
            resD3Array[i] = tem.getDiceRes();
            Debug.Log(tem.getDiceRes());
            _RollD3resSUM += tem.getDiceRes();
        }
        Debug.Log(dice3Amount + " 颗三面骰子的和 " + _RollD3resSUM);

        for (int i = 0; i < dice6Amount; i++)
        {
            Dice tem = new Dice6();
            tem.Roll();
            resD6Array[i] = tem.getDiceRes();
            Debug.Log(tem.getDiceRes());
            _RollD6resSUM += tem.getDiceRes();
        }
        Debug.Log(dice6Amount + " 颗六面骰子的和 " + _RollD6resSUM);
        return(_RollD3resSUM + _RollD6resSUM);
    }
예제 #2
0
    public int calculateDice(int dic3, int dic6)
    {
        resD3Array = new int[dic3];
        int _RollD3resSUM = 0;

        resD6Array = new int[dic6];
        int _RollD6resSUM = 0;

        for (int i = 0; i < dic3; i++)
        {
            Dice tem = new Dice3();
            tem.Roll();
            resD3Array[i] = tem.getDiceRes();
            //            Debug.Log(tem.getDiceRes());
            _RollD3resSUM += tem.getDiceRes();
        }
        //		Debug.Log(dic3 + " 颗三面骰子的和 " + _RollD3resSUM);

        for (int i = 0; i < dic6; i++)
        {
            Dice tem = new Dice6();
            tem.Roll();
            resD6Array[i] = tem.getDiceRes();
            //            Debug.Log(tem.getDiceRes());
            _RollD6resSUM += tem.getDiceRes();
        }
        //		Debug.Log(dic6+ " 颗六面骰子的和 " + _RollD6resSUM);
        int _sum = _RollD3resSUM + _RollD6resSUM;

        //  Debug.Log(dic3 + " 颗三面骰子和 " + dic6 + " 颗六面骰子的结果为 " + _sum);
        return(_RollD3resSUM + _RollD6resSUM);
    }
예제 #3
0
        public void not_all_rolls_should_be_the_same()
        {
            var result = new List <int>();

            for (int i = 0; i < 50; i++)
            {
                var numberDice = new Dice6();
                numberDice.Roll();
                result.Add(numberDice.Value);
            }

            // We are really unlucky if this by accident passes
            Assert.IsFalse(result.All(r => r == result[0]));
        }
예제 #4
0
        public void Dice_Test()
        {
            NDice dice = new NDice(6);

            for (int i = 0; i < 20; i++)
            {
                Assert.AreEqual(InRange(dice.Roll(), 1, 7), true);
            }

            dice = new Dice6();

            for (int i = 0; i < 20; i++)
            {
                Assert.AreEqual(InRange(dice.Roll(), 1, 7), true);
            }

            dice = new Dice8();

            for (int i = 0; i < 20; i++)
            {
                Assert.AreEqual(InRange(dice.Roll(), 1, 9), true);
            }

            dice = new Dice12();

            for (int i = 0; i < 20; i++)
            {
                Assert.AreEqual(InRange(dice.Roll(), 1, 13), true);
            }


            DiceCup cup = new DiceCup(6, 2);

            int[] results;
            for (int i = 0; i < 20; i++)
            {
                results = cup.Roll();

                foreach (int result in results)
                {
                    Assert.AreEqual(InRange(result, 1, 7), true);
                }

                Assert.AreEqual(InRange(results.Sum(), 2, 13), true);
            }


            DynamicDiceCup dynamicCup = new DynamicDiceCup();

            dynamicCup += new Dice12();
            dynamicCup.PushDice(new Dice6());


            for (int i = 0; i < 20; i++)
            {
                results = dynamicCup.Roll();

                Assert.AreEqual(InRange(results[0], 1, 13), true);
                Assert.AreEqual(InRange(results[1], 1, 7), true);

                Assert.AreEqual(InRange(results.Sum(), 2, 19), true);
            }

            dynamicCup--;

            Assert.AreEqual(dynamicCup.Count, 1);

            Assert.AreEqual(dynamicCup.PopDice().GetType(), typeof(Dice12));

            Assert.AreEqual(dynamicCup.Count, 0);

            try
            {
                dynamicCup.Roll();
                throw new Exception("Roll() didn't throw an exception. It should have been empty.");
            }
            catch (InvalidOperationException) { }
        }