public override async Task OnConnected() { await Task.Run(() => { var newPlayerName = GetCurrentUserName(); if (newPlayerName == null) return; var newPlayer = new Player(newPlayerName) {ConnectionId = Context.ConnectionId}; _lobby.AddPlayer(newPlayer); }); }
private void InitializeClient(Player player) { var gameSession = player.Room.GameSession; var gamePlayer = gameSession.Players.Single(p => p.Name == player.Name); Clients.Client(player.ConnectionId) .init(new { cards = gamePlayer.Cards.Select(SerializeCard), topCard = SerializeCard(gameSession.DiscardPileTop), otherPlayers = gameSession.Players.Except(new [] { gamePlayer }).Select(p => new {name = p.Name, cardsCount = p.Cards.Count}), deck = gameSession.Game.Cards.Count }); ToClientWithName(gameSession.CurrentPlayer.Name).activate(); }
public void AddPlayer(Player player) { if (_allPlayers.All(p => p.Name != player.Name)) _allPlayers.Add(player); }