示例#1
0
        public bool AddClient(NetworkConnection client, int[] playerTeamWish)
        {
            if (GameStructure.MissingPlayersCount < playerTeamWish.Length)
            {
                return(false);
            }

            Client newClient = new Client(GameStructure, client.ClientSession.SessionID);

            Clients.Add(newClient);


            int maxTeamSize = GameStructure.maxPlayers / 2;

            foreach (int team in playerTeamWish)
            {
                int index         = GameStructure.PlayersCount;
                int teamIndex     = GameStructure.GameTeams[team].PlayerList.Count;
                int teamOpenSpots = maxTeamSize - teamIndex;

                if (teamOpenSpots < 1)
                {
                    continue;
                }

                Player newPlayer = new Player(index, team, GameInitializers.GetPlayerX(team, teamIndex));
                newPlayer.Height    = GameInitializers.GetPlayerHeight(maxTeamSize);
                newPlayer.PositionY = GameInitializers.GetPlayerY(maxTeamSize);

                newClient.AddPlayer(newPlayer);
                GameStructure.AddPlayer(newPlayer);
            }

            if (GameStructure.PlayersCount == NumberOfPlayers)
            {
                GameState = GameStates.Ready;
            }


            Network.AddClientConnection(client);
            return(true);
        }