Пример #1
0
        public void TableChanged(int tableId, IPlayTableService playTableService)
        {
            var tablePlayers = playTableService.GetPlayersOfTable(tableId);
            var tableViewers = playTableService.GetTableViewer(tableId);
            var tableState   = TableHubUtils.GetTableState(tableId, playTableService, _mapper);

            Parallel.ForEach(tablePlayers, (tablePlayer) =>
            {
                var clientUser = getClientUser(tablePlayer.PlayerId);
                if (clientUser != null)
                {
                    clientUser.PlayerTableState(tableState);
                }
            });

            // for all viewers of the table
            Parallel.ForEach(tableViewers, (tableViewer) =>
            {
                var clientUser = getClientUser(tableViewer.userId);
                if (clientUser != null)
                {
                    clientUser.SpectatorTable(tableState);
                }
            });
        }
Пример #2
0
        public static PlayTableStaeModel GetTableState(int tableId, IPlayTableService playTableService, IMapper mapper)
        {
            var table = playTableService.GetTableById(tableId);

            if (table != null)
            {
                var tablePlayers = playTableService.GetPlayersOfTable(tableId);
                var tableState   = mapper.Map <PlayTableStaeModel>(table);
                tableState.UserCount     = tablePlayers.Length;
                tableState.TableId       = table.Id;
                tableState.Players       = tablePlayers.Select((p) => new AdditionPlayerInfoModel(p)).ToArray();
                tableState.ShuffleCount  = tablePlayers.Count(p => p.ShuffleRound);
                tableState.NextTurnCount = tablePlayers.Count(p => p.NextTurn);
                return(tableState);
            }
            return(null);
        }