/// <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); } }
/// <inheritdoc/> public IList <string> GetActivePlayersInLobby(string host) { ServiceMatch match = GetMatch(host); ServiceLobby lobby = match.Lobby; IList <string> activePlayersFromMatch = lobby.GetUsernamesOfPlayersConnectedToLobby(); return(activePlayersFromMatch); }
/// <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); } }
/// <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); } } }
/// <summary> /// Constructor of the class. /// </summary> public MatchDto() { Lobby = new ServiceLobby(); }
/// <summary> /// Constructor of the class. /// </summary> public ServiceMatch() { Lobby = new ServiceLobby(); _players = new List <ServicePlayer>(); }