private void CheckWagerIsValid(Wager currentWager, Wager previousWager) { const int minFaceValue = 1; const int maxFaceValue = 6; if (!(maxFaceValue >= currentWager.FaceValue && currentWager.FaceValue >= minFaceValue)) { throw new InvalidWagerException($"The face value must be between {minFaceValue} and {maxFaceValue}"); } if (currentWager.DiceCount <= 0 || currentWager.DiceCount > GetActiveDiceCount()) { throw new InvalidWagerException("The wager must be a positive value no greater than the number of dice in play"); } if (currentWager.DiceCount < previousWager.DiceCount) { throw new InvalidWagerException("The player must wager a number of dice equal to or greater than the previoius wager"); } if (currentWager.DiceCount != previousWager.DiceCount) { return; } if (currentWager.FaceValue > previousWager.FaceValue) { return; } throw new InvalidWagerException("If the number of dice are the same, the player must wager a higher face value"); }
public Wager GetWager() { Console.WriteLine($"{_playerName}, it's your turn!\n"); while (true) { var wager = new Wager(); Console.WriteLine("(R)aise or (C)hallenge?:"); var answer = Console.ReadLine(); switch (answer) { case "R": Console.WriteLine("How many dice?:"); wager.DiceCount = int.Parse(Console.ReadLine()); Console.WriteLine("Face value? (1-6):"); wager.FaceValue = int.Parse(Console.ReadLine()); break; case "C": wager.isChallenge = true; break; default: Console.WriteLine("Please type 'R' or 'C'"); continue; } return(wager); } }
private void CheckWager(Wager currentWager, Wager previousWager) { if (currentWager.isChallenge) { DetermineWinnner(previousWager); } else { CheckWagerIsValid(currentWager, previousWager); } }
private void DetermineWinnner(Wager previousWager) { var allDice = GetAllDice(); var actualCount = allDice.Count(d => d.currentValue == previousWager.FaceValue); if (actualCount >= previousWager.DiceCount) { if (_activePlayer.Previous != null) { _winner = _activePlayer.Previous.Value; } _loser = _activePlayer.Value; } else { _winner = _activePlayer.Value; if (_activePlayer.Previous != null) { _loser = _activePlayer.Previous.Value; } } }