Ejemplo n.º 1
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);
    }
Ejemplo n.º 2
0
 public Yatzy()
 {
     for (int i = 0; i < 5; i++)
     {
         _dices[i] = new Dice6();
     }
 }
Ejemplo n.º 3
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);
    }
Ejemplo n.º 4
0
 public Yatzy(Dice6 d1, Dice6 d2, Dice6 d3, Dice6 d4, Dice6 d5)
 {
     _dices[0] = d1;
     _dices[1] = d2;
     _dices[2] = d3;
     _dices[3] = d4;
     _dices[4] = d5;
 }
Ejemplo n.º 5
0
        public void throwSeverald3Test()
        {
            Dice dice = new Dice6(new VisualStudioRandomGenerator());

            for (int i = 0; i < 100; i++)
            {
                int dvalue = (int)dice.rollADice();
                Assert.IsTrue(1 <= dvalue && dvalue <= 6, "value not fit for d6:" + dvalue);
            }
        }
Ejemplo n.º 6
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]));
        }
Ejemplo n.º 7
0
        public BattleDie TryAddDie(Die die, BattleGameDieUI uiDie)
        {
            BattleDie battleDie = null;
            bool      add       = true;

#if TEAM_BATTLE
            add = (die.dieType == Die.DieType.SixSided) ? (Dice6?.Count() < _teamNumD6) : (Dice20?.Count() < _teamNumD20);
#endif
            if (add)
            {
                battleDie = new BattleDie(die, TeamNumber, uiDie);
                _dice.Add(battleDie);
            }
            return(battleDie);
        }
Ejemplo n.º 8
0
        public void throw1d6Test()
        {
            Dice dice = new Dice6(new FakeRandomGenerator());

            Assert.AreEqual(DiceValue.PlusOne, dice.rollADice());
        }
Ejemplo n.º 9
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) { }
        }