Esempio n. 1
0
        /// <inheritdoc/>
        public bool CanJoin(string matchHost)
        {
            ServiceMatch gameMatch = GetMatch(matchHost);

            if (gameMatch == null)
            {
                MatchAccessDeniedFault matchAccessDeniedFault = new MatchAccessDeniedFault()
                {
                    Details = "The match does not exist."
                };
                throw new FaultException <MatchAccessDeniedFault>(matchAccessDeniedFault);
            }
            else
            {
                ServiceLobby lobby = gameMatch.Lobby;
                IList <ServicePlayerInLobby> playersConnectedToLobby = lobby.GetPlayersConnectedToLobby();
                int  numberOfPlayersConnectedToLobby = playersConnectedToLobby.Count;
                int  numberOfPlayersRequired         = gameMatch.MaxNumberOfPlayers;
                bool matchHasStarted = gameMatch.HasStarted;
                bool ThereIsSpaceForAnotherPlayer = false;

                if (numberOfPlayersConnectedToLobby < numberOfPlayersRequired)
                {
                    ThereIsSpaceForAnotherPlayer = true;
                }

                if (ThereIsSpaceForAnotherPlayer && !matchHasStarted)
                {
                    return(true);
                }
                return(false);
            }
        }
Esempio n. 2
0
        /// <inheritdoc/>
        public IList <string> GetActivePlayersInLobby(string host)
        {
            ServiceMatch   match = GetMatch(host);
            ServiceLobby   lobby = match.Lobby;
            IList <string> activePlayersFromMatch = lobby.GetUsernamesOfPlayersConnectedToLobby();

            return(activePlayersFromMatch);
        }
Esempio n. 3
0
        /// <inheritdoc/>
        public void JoinLobby(string host, string username)
        {
            ServiceMatch match = GetMatch(host);

            if (match != null)
            {
                ServiceLobby lobby = match.Lobby;
                lobby.AddPlayerToLobby(host, username);
                lobby.NotifyNewPlayerEnteredLobby(username);
            }
        }
Esempio n. 4
0
        /// <inheritdoc/>
        public void LeaveLobby(string host, string username)
        {
            ServiceMatch match = GetMatch(host);

            if (match != null)
            {
                ServiceLobby lobby = match.Lobby;
                lobby.RemovePlayerFromLobby(username);
                if (host.Equals(username))
                {
                    lobby.NotifyPlayersMatchHasBeenDeleted();
                    _matches.Remove(match);
                }
                else
                {
                    lobby.NotifyOnePlayerLeftLobby(username);
                }
            }
        }
Esempio n. 5
0
 /// <summary>
 /// Constructor of the class.
 /// </summary>
 public MatchDto()
 {
     Lobby = new ServiceLobby();
 }
Esempio n. 6
0
 /// <summary>
 /// Constructor of the class.
 /// </summary>
 public ServiceMatch()
 {
     Lobby    = new ServiceLobby();
     _players = new List <ServicePlayer>();
 }