public void SetPlayerDicesQty(Player player, int delta) { PlayerCups.First(pc => pc.Player == player).DicesQuantity += delta; if (delta < 0) { DiceLoser = player; } else { DiceWinner = player; } Table.SetNextPlayer(player); }
public GameChangeResult End(GameAction endAction) { IsEnded = true; EndAction = endAction; // transition lock status if (HasLock) { PlayerCups.First(pc => pc.LockStatus == LockStatus.Locking).LockStatus = LockStatus.Unavailable; } // highlight matching dices foreach (var matchingDice in PlayerCups.SelectMany(pc => pc.Dices).Where(d => d.Value == Dice.Value || d.Value == 1)) { matchingDice.IsHighlighted = true; } // check if table ends var playersWithDices = PlayerCups.Where(pc => pc.DicesQuantity > 0).Select(pc => pc.Player); if (playersWithDices.Count() == 1) { Table.End(playersWithDices); } var gameEndResult = new GameChangeResult(new { actualQuantity = ActualQuantity, playerCups = PlayerCups.Select(pc => pc.ToClient()), table = new { status = Table.Status.ToString(), activePlayerName = Table.ActivePlayer?.Name, stats = Table.GetStats(), winnerNames = Table.Winners.Select(p => p.Name) }, isEnded = IsEnded, winnerNames = Winners.Select(p => p.Name), endActionName = EndAction?.Name, diceLoserName = DiceLoser?.Name, diceWinnerName = DiceWinner?.Name }); return(gameEndResult); }
public override bool IsEliminated(Player player) { return(PlayerCups.First(pc => pc.Player == player).DicesQuantity <= 0); }