Example #1
0
        public Player AddNewPlayer(
            string name,
            UserRole role = UserRole.Player,
            Team?team     = null,
            int?number    = null)
        {
            if (!number.HasValue)
            {
                number = Players.Max(x => x.Number) + 1;
            }

            if (!team.HasValue)
            {
                team = RedPlayers.Count() > BluePlayers.Count()
                                        ? Team.Blue
                                        : Team.Red;
            }

            var player = new Player(
                name,
                team.Value,
                role,
                number.Value);

            AddPlayer(player);

            AddPublicEvent(GameEvent.PlayerJoinedGame(player, DateTime.Now));

            return(player);
        }
Example #2
0
        public IPlayer GetPlayerById(ulong id)
        {
            IPlayer player = BluePlayers.FirstOrDefault(p => p.Id == id);

            if (player == null)
            {
                player = RedPlayers.FirstOrDefault(p => p.Id == id);
            }

            return(player);
        }
Example #3
0
        public IPlayer GetPlayerByGuid(string guid)
        {
            IPlayer player = BluePlayers.FirstOrDefault(p => p.Guid.ToString() == guid);

            if (player == null)
            {
                player = RedPlayers.FirstOrDefault(p => p.Guid.ToString() == guid);
            }

            return(player);
        }
Example #4
0
 public void RemovePlayer(ulong id)
 {
     try
     {
         RedPlayers.RemoveAll(c => c.Id == id);
         BluePlayers.RemoveAll(c => c.Id == id);
     }
     catch (Exception)
     {
         Console.WriteLine("RedPlayers count : {0}", RedPlayers.Count);
         Console.WriteLine("BluePlayers count : {0}", BluePlayers.Count);
     }
 }