Esempio n. 1
0
        public GameConnection TryAddPlayer(GameWebSocketService client, string name)
        {
            lock (gameLock)
            {
                if (Started)
                {
                    return(null);
                }

                clients.Add(client);
                var player = new Player(name);
                game.AddPlayer(player);

                if (clients.Count == config.NumberOfPlayers)
                {
                    StartGame();
                }

                return(new GameConnection(client, player, this));
            }
        }
Esempio n. 2
0
        public GameConnection JoinGame(GameWebSocketService gameService, string nickname, int gameSize)
        {
            GameConfiguration config     = GameConfiguration.FromNumberOfPlayers(gameSize);
            GameConnection    connection = null;

            while (connection == null)
            {
                HostedGame game = games.GetOrAdd(config, c => new HostedGame(c));

                if (game.Started)
                {
                    games.TryUpdate(config, new HostedGame(config), game);
                }
                else
                {
                    connection = game.TryAddPlayer(gameService, nickname);
                }
            }

            return(connection);
        }
Esempio n. 3
0
 internal GameConnection(GameWebSocketService client, Player player, HostedGame hostedGame)
 {
     this.Client = client;
     this.Player = player;
     this.hostedGame = hostedGame;
 }
Esempio n. 4
0
        public GameConnection JoinGame(GameWebSocketService gameService, string nickname, int gameSize)
        {
            GameConfiguration config = GameConfiguration.FromNumberOfPlayers(gameSize);
            GameConnection connection = null;

            while (connection == null)
            {
                HostedGame game = games.GetOrAdd(config, c => new HostedGame(c));

                if (game.Started)
                {
                    games.TryUpdate(config, new HostedGame(config), game);
                }
                else
                {
                    connection = game.TryAddPlayer(gameService, nickname);
                }
            }

            return connection;
        }
Esempio n. 5
0
        public GameConnection TryAddPlayer(GameWebSocketService client, string name)
        {
            lock (gameLock)
            {
                if (Started)
                    return null;

                clients.Add(client);
                var player = new Player(name);
                game.AddPlayer(player);

                if (clients.Count == config.NumberOfPlayers)
                    StartGame();

                return new GameConnection(client, player, this);
            }
        }
Esempio n. 6
0
 internal GameConnection(GameWebSocketService client, Player player, HostedGame hostedGame)
 {
     this.Client     = client;
     this.Player     = player;
     this.hostedGame = hostedGame;
 }