예제 #1
0
파일: Game.cs 프로젝트: piotrekradomski/SE
 private MessageProject.Role CheckRolePreference(MessageProject.Team teamToAdd, MessageProject.Role preferredRole)
 {
     if (teamToAdd.Equals(MessageProject.Team.blue))
     {
         if (preferredRole.Equals(MessageProject.Role.leader) && blueLeaderId == -1)
         {
             return(MessageProject.Role.leader);
         }
         else
         {
             return(MessageProject.Role.member);
         }
     }
     else
     {
         if (preferredRole.Equals(MessageProject.Role.member) && redLeaderId == -1)
         {
             return(MessageProject.Role.leader);
         }
         else
         {
             return(MessageProject.Role.member);
         }
     }
 }
예제 #2
0
파일: Game.cs 프로젝트: piotrekradomski/SE
        public Tuple <int, MessageProject.Team, MessageProject.Role, bool> MakePlayer(MessageProject.Role preferredRole, MessageProject.Team preferredTeam, int playerID)
        {
            // Returns new ID associated with player created, his team, his final role
            lock (gameState)
            {
                if (gameState.gameStarted)
                {
                    Console.WriteLine("Rejecting game join since game has already started!");
                    return(new Tuple <int, MessageProject.Team, MessageProject.Role, bool>(-999, MessageProject.Team.red, MessageProject.Role.member, false));
                }
            }
            lock (playersDictionary) // to avoid overwriting adds and current ammount read
            {
                // Now spot is guaranteed, whether as preferred or not
                // Make returned structure equivalent to response message
                Player newPlayer   = new Player();
                int    newPlayerID = playerID; // acts as GUID since 1 game atm, increasing order
                playersDictionary.Add(newPlayerID, newPlayer);
                Console.WriteLine("Added new player ID: {0}", newPlayerID);
                MessageProject.Team teamToAdd = CheckTeamPreference(preferredTeam);
                newPlayer.team = teamToAdd;
                if (teamToAdd.Equals(MessageProject.Team.red))
                {
                    redTeam.Add(newPlayerID);
                }
                else
                {
                    blueTeam.Add(newPlayerID);
                }

                MessageProject.Role roleToGive = CheckRolePreference(teamToAdd, preferredRole);
                if (roleToGive.Equals(MessageProject.Role.leader))
                {
                    if (teamToAdd.Equals(MessageProject.Team.blue))
                    {
                        blueLeaderId = newPlayerID;
                    }
                    else
                    {
                        redLeaderId = newPlayerID;
                    }
                }
                newPlayer.role = roleToGive;
                // Add PosX, PosY, randomize, update both playerobj and field containing player info
                // Global update when dict full, just before sending Game message to start it
                bool gameJustStarted = false;
                if (playersDictionary.Count() >= 2 * settings.PlayersPerTeam)
                {
                    gameJustStarted = true;
                }
                return(Tuple.Create(newPlayerID, teamToAdd, roleToGive, gameJustStarted));
            }
        }
예제 #3
0
파일: Game.cs 프로젝트: piotrekradomski/SE
 private MessageProject.Team CheckTeamPreference(MessageProject.Team preferredTeam)
 {
     // Checks which team to add player to, assumes correct data options
     if ((preferredTeam.Equals(MessageProject.Team.red) && redTeam.Count() < settings.PlayersPerTeam) ||
         (preferredTeam.Equals(MessageProject.Team.blue) && blueTeam.Count() >= settings.PlayersPerTeam))
     {
         return(MessageProject.Team.red);
     }
     else
     {
         return(MessageProject.Team.blue);
     }
 }