Esempio n. 1
0
        public ObtainingATwoPair()
        {
            var diceSet  = new DiceRoll(_bothPairs);
            var pairRule = new PairRule();

            result = pairRule.CountPoints(diceSet);
        }
Esempio n. 2
0
 public DieRollResult CountPoints(DiceRoll diceRoll)
 {
     if (IsApplicable(diceRoll))
     {
         return(new DieRollResult(DiceCombination.FiveOfAKind, _points));
     }
     return(DieRollResult.Default());
 }
Esempio n. 3
0
 public DieRollResult CountPoints(DiceRoll diceRoll)
 {
     if (!IsApplicable(diceRoll))
     {
         return(DieRollResult.Default());
     }
     return(Combination(diceRoll));
 }
Esempio n. 4
0
        public ObtainingAHighStraight()
        {
            var dice    = new DieRoll[] { DieRoll.Two, DieRoll.Four, DieRoll.Three, DieRoll.Five, DieRoll.Six };
            var diceSet = new DiceRoll(dice);
            var rule    = new StraightRule();

            result = rule.CountPoints(diceSet);
        }
Esempio n. 5
0
 public DieRollResult CountPoints(DiceRoll diceRoll)
 {
     if (IsApplicable(diceRoll))
     {
         return(new DieRollResult(DiceCombination.ThreeOfAKind, GetPoints(diceRoll)));
     }
     else
     {
         return(DieRollResult.Default());
     }
 }
Esempio n. 6
0
 public DieRollResult CountPoints(DiceRoll diceRoll)
 {
     if (IsApplicable(diceRoll))
     {
         return(new DieRollResult(DiceCombination.FullHouse, _points));
     }
     else
     {
         return(DieRollResult.Default());
     }
 }
Esempio n. 7
0
    public IEnumerator RollDice(DieRollResult cb)
    {
        if (!areDiceAtRest())
        {
            return(false);
        }

        Vector3    savedCamPos = diceCam.transform.position;
        Quaternion savedCamRot = diceCam.transform.rotation;

        diceCam.camera.enabled = true;

        foreach (Die die in dice)
        {
            die.transform.position = transform.position;
            die.transform.rotation = Random.rotation;

            die.rigidbody.AddForce(dieInitialForce);
            die.rigidbody.AddTorque(dieInitialTorque);

            yield return(new WaitForSeconds(timeBetweenDieThrows));
        }

        yield return(new WaitForSeconds(minTimeToWaitAfterThrow));

        while (!areDiceAtRest())
        {
            Vector3 avgPos = avgDicePos();
            diceCam.transform.position = Vector3.Lerp(savedCamPos, avgPos, distanceFromDice);
            diceCam.transform.LookAt(avgPos);
            yield return(new WaitForEndOfFrame());
        }

        yield return(new WaitForSeconds(delayAfterDiceResult));

        diceCam.camera.enabled = false;

        diceCam.transform.position = savedCamPos;
        diceCam.transform.rotation = savedCamRot;

        cb(dice[0].GetResult(), dice[1].GetResult());
    }
Esempio n. 8
0
        public DieRollResult CountPoints(DiceRoll diceRoll)
        {
            var dice = diceRoll.AllDice.ToIntArray().OrderBy(x => x).ToArray();

            if (dice.Distinct().Count() != 5)
            {
                return(DieRollResult.Default());
            }
            else
            {
                if (dice.Any((x => x == (int)DieRoll.One)) && IsSequenceConsecutive(dice))
                {
                    return(new DieRollResult(DiceCombination.StraightLow, _points));
                }
                else if (IsSequenceConsecutive(dice))
                {
                    return(new DieRollResult(DiceCombination.StraightHigh, _points));
                }
                else
                {
                    return(DieRollResult.Default());
                }
            }
        }
Esempio n. 9
0
 public static DieRollResult Max(DieRollResult first, DieRollResult second)
 {
     // TODO:
     // Create logic for rules overriding
     return(first.Points > second.Points ? first : second);
 }