Exemplo n.º 1
0
 public override Dictionary <Player, object> GetPlayerGameStates()
 {
     return(PlayerCups.ToDictionary(
                pc => pc.Player,
                pc => (object)new { dices = pc.Dices.Select(d => d.ToClient(true)) }
                ));
 }
Exemplo n.º 2
0
 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);
 }
Exemplo n.º 3
0
        public override object ToClient()
        {
            var client = new {
                playerCups     = PlayerCups.Select(pc => pc.ToClient()),
                quantity       = Quantity,
                dice           = Dice.ToClient(),
                hasLock        = HasLock,
                actualQuantity = ActualQuantity,
                endActionName  = EndAction?.Name,
                diceLoserName  = DiceLoser?.Name,
                diceWinnerName = DiceWinner?.Name
            };

            return(client.Merge(base.ToClient()));
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
 public override bool IsEliminated(Player player)
 {
     return(PlayerCups.First(pc => pc.Player == player).DicesQuantity <= 0);
 }