Example #1
0
        public void RemovePlayer(string socketId)
        {
            Players.RemoveAll(o => o.SocketId == socketId);
            PendingGame activeGame = Games.FirstOrDefault(o => o.Players.Exists(p => p.SocketId == socketId));

            if (activeGame != null)
            {
                activeGame.Players.RemoveAll(o => o.SocketId == socketId);
            }
        }
Example #2
0
        public void LeaveCurrentGame(int playerId)
        {
            PendingGame activeGame = Games.FirstOrDefault(o => o.Players.Exists(p => p.Id == playerId));

            if (activeGame != null)
            {
                activeGame.Players.RemoveAll(o => o.Id == playerId);
            }
            PlayerDetails player = Players.FirstOrDefault(o => o.Id == playerId);

            player.IsGamePending = false;
            player.IsGameActive  = false;
        }
Example #3
0
        public void PlayerReady(PlayerReadyrequest request)
        {
            PendingGame activeGame = Games.FirstOrDefault(o => o.Players.Exists(p => p.Id == request.PlayerId));

            if (activeGame != null)
            {
                GamePlayer player = activeGame.Players.FirstOrDefault(o => o.Id == request.PlayerId);
                if (player != null)
                {
                    player.IsReady = request.Ready;
                }
                activeGame.StartGame = (activeGame.Players.Count == activeGame.PlayerCount && activeGame.Players.FirstOrDefault(o => !o.IsReady) == null);
            }
        }
Example #4
0
        public void AddGame(CreateGameRequest request)
        {
            PendingGame   newGame    = new PendingGame(request);
            PlayerDetails player     = Players.FirstOrDefault(o => o.Id == request.PlayerId);
            PendingGame   activeGame = Games.FirstOrDefault(o => o.Players.Exists(p => p.Id == player.Id));

            if (activeGame != null)
            {
                activeGame.Players.RemoveAll(o => o.Id == player.Id);
            }
            newGame.Players.Add(new GamePlayer(player));
            player.IsGamePending = true;
            player.IsGameActive  = false;
            Games.Add(newGame);
        }
Example #5
0
        public void JoinGame(JoinGameRequest request)
        {
            PlayerDetails player = Players.FirstOrDefault(o => o.Id == request.PlayerId);

            if (player != null)
            {
                PendingGame activeGame = Games.FirstOrDefault(o => o.Players.Exists(p => p.Id == request.PlayerId));
                if (activeGame != null)
                {
                    activeGame.Players.RemoveAll(o => o.Id == request.PlayerId);
                }
                PendingGame joinGame = Games.FirstOrDefault(o => o.Id.ToString() == request.GameId);
                if (joinGame != null)
                {
                    joinGame.Players.Add(new GamePlayer(player));
                }
                player.IsGamePending = true;
                player.IsGameActive  = false;
            }
        }