public Word join(string playerName) { //if nobody is hosting the game, they can't join as a player. if (currentUserHostingGame == null) { NoGameHostedFault nobodyHere = new NoGameHostedFault(); nobodyHere.problem = "No one is hosting the game. It is sad day. :c"; throw new FaultException <NoGameHostedFault>(nobodyHere); } //if activeplayers count is five, throw an exception. if (activePlayers.Count + 1 > MAX_ALLOWED_PLAYERS) { MaximumPlayersReachedFault maximumPlayersFault = new MaximumPlayersReachedFault(); maximumPlayersFault.playerName = playerName; maximumPlayersFault.problem = "Maximum players reached: " + MAX_ALLOWED_PLAYERS.ToString(); throw new FaultException <MaximumPlayersReachedFault>(maximumPlayersFault); } //if the host's name is taken, they can't join as a player if (playerName == currentUserHostingGame) { HostCannotJoinGameFault hostJoinFault = new HostCannotJoinGameFault(); hostJoinFault.userName = playerName; hostJoinFault.problem = "You are already hosting, you cannot join as a player."; throw new FaultException <HostCannotJoinGameFault>(hostJoinFault); } else { activePlayers.Add(playerName); return(gameWord); } }
public Word join(string playerName) { //if nobody is hosting the game, they can't join as a player. if (currentUserHostingGame == null) { NoGameHostedFault nobodyHere = new NoGameHostedFault(); nobodyHere.problem = "No one is hosting the game. It is sad day. :c"; throw new FaultException<NoGameHostedFault>(nobodyHere); } //if activeplayers count is five, throw an exception. if (activePlayers.Count + 1 > MAX_ALLOWED_PLAYERS) { MaximumPlayersReachedFault maximumPlayersFault = new MaximumPlayersReachedFault(); maximumPlayersFault.playerName = playerName; maximumPlayersFault.problem = "Maximum players reached: " + MAX_ALLOWED_PLAYERS.ToString(); throw new FaultException<MaximumPlayersReachedFault>(maximumPlayersFault); } //if the host's name is taken, they can't join as a player if(playerName == currentUserHostingGame) { HostCannotJoinGameFault hostJoinFault = new HostCannotJoinGameFault(); hostJoinFault.userName = playerName; hostJoinFault.problem = "You are already hosting, you cannot join as a player."; throw new FaultException<HostCannotJoinGameFault>(hostJoinFault); } else { activePlayers.Add(playerName); return gameWord; } }