public void ApplyCombinationForPlayer(IPlayer player, IDices dices) { int score = CalculateScore(dices); _playerScores[player] = score; _playerUsed[player] = true; }
private int Full(IDices dices) { int[] nums = new int[6]; int firstValue = dices.GetValues()[0]; int secondValue = -1; foreach (int value in dices.GetValues()) { if (value != firstValue) { secondValue = value; } } int countFirst = 0; int countSecond = 0; foreach (int value in dices.GetValues()) { if (value == firstValue) { countFirst++; } if (value == secondValue) { countSecond++; } } if (((countSecond == 3) && (countFirst == 2)) || ((countFirst == 3) && (countSecond == 2))) { return(25); } return(0); }
public override int CalculateScore(IDices dices) { int[] values = new int[5]; values = dices.GetValues(); Array.Sort(values); switch (_name) { case "Small Straight": if (Straight(values) > 3) { return(30); } break; case "Large Straight": if (Straight(values) > 4) { return(40); } break; default: throw new ArgumentException("name not valid: " + Name); } return(0); }
public override int CalculateScore(IDices dices) { switch (Name) { case "Tris": if (HowManyEquals(dices) > 2) { return(Sum(dices)); } break; case "Poker": if (HowManyEquals(dices) > 3) { return(Sum(dices)); } break; case "Yahtzee": if (HowManyEquals(dices) == 5) { return(50); } break; case "Full": return(Full(dices)); case "Chance": return(Sum(dices)); default: throw new ArgumentException("name not valid: " + Name); } return(0); }
private int Sum(IDices dices) { int res = 0; foreach (int value in dices.GetValues()) { res += value; } return(res); }
public void RollDices(IDices dices) { _remainingRolls--; dices.Roll(); if (RemainingRolls < 1) { FinishedRolls?.Invoke(this, EventArgs.Empty); } }
public void SetCombinationForPlayer(IPlayer player, Combination c, IDices dices) { if (c.UsedByPlayer(player)) { throw new ArgumentException("Combination already set!"); } c.ApplyCombinationForPlayer(player, dices); Console.WriteLine("Player " + player.Name + " applied combination " + c.Name + ", with a score of " + c.CalculateScore(dices) + "."); OnCombinationApplied(c); }
public Game(List <IPlayer> players) { // Do stuff _players = players; _dices = DicesFactory.getIDicesInstance(); _currentTurn = 0; _turns = new ITurn[TURNS]; _scoreboard = new Scoreboard(players); NewTurn(); OnStart(); }
override public int CalculateScore(IDices dices) { int result = 0; int[] values = dices.GetValues(); for (int i = 0; i < values.Length; i++) { if (values[i] == _diceValue) { result += _diceValue; } } return(result); }
private int HowManyEquals(IDices dices) { int[] nums = new int[6]; foreach (int value in dices.GetValues()) { nums[value - 1]++; } int max = 0; foreach (int val in nums) { if (val > max) { max = val; } } return(max); }
abstract public int CalculateScore(IDices dices);
public MagicItemCreation(IDices dices) { InitMagicItemsTable(); Dices = dices; }
public static void Instantiate(IDices dicesDependency) { _instance = new MagicItemCreation(dicesDependency); }
public Board(IDashCell dashCell, IDices dices) { this.dashCell = dashCell; this.game = dashCell.GetGame(); this.dices = dices; }
public void UseCombination(Scoreboard sb, Combination c, IDices dices) { sb.SetCombinationForPlayer(_player, c, dices); TurnEnded?.Invoke(this, EventArgs.Empty); }