Skip to content

Commit

Permalink
Merge pull request #436 from Advanced-Programming-2021/spellsAndSpeci…
Browse files Browse the repository at this point in the history
…lMonsters

show result after canceling match
  • Loading branch information
amir-haji authored Jul 21, 2021
2 parents 9ce07e2 + 25551e9 commit 95e8934
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 13 deletions.
3 changes: 3 additions & 0 deletions src/main/java/Client/ClientServer/ClientUpdater.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ private void handleResponse(String serverResponse) {
lobbyMenuGui.startLobbyCoinTossMenu((String) fields[0], (boolean) fields[1]);
else if (methodName.equals("startRefuseMatchView"))
matchMakingMenuGui.startRefuseMatchView((String) fields[0]);
else if (methodName.equals("startRefusedMatchView")) {

}

// Scoreboard Methods:
if (methodName.equals("updateScoreboard")
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/Client/view/LobbyMenuGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ public void startLobbyCoinTossMenu(String opponentUsername, boolean isWinner) {
}
}

public void startRefusedMatchView(String username) {
ShowOutput.showOutput("Error", "the " + username + " refused duel with you!");
}

public void showPinnedMessages(MouseEvent mouseEvent) {
showPinnedMessagesPopUpWindow = new Stage();
showPinnedMessagesPopUpWindow.initModality(Modality.APPLICATION_MODAL);
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/Server/controller/ClientUpdateController.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ public void startRefuseMatchView(String opponentUsername) {
ClientUpdateHandler.addClientUpdate(user, update);
}

public void startRefusedMatchView(String username) {
String update = ClientUpdateHandler.getUpdateStringFormat("startRefusedMatchView", username);
ClientUpdateHandler.addClientUpdate(user, update);
}

// Methods that shouldn't be used:
public ArrayList<Integer> getCardsForTribute(int n) {
// return (ArrayList<Integer>) getMethodResult("getCardsForTribute", n);
Expand Down
42 changes: 29 additions & 13 deletions src/main/java/Server/controller/MatchMakingController.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,36 @@ else if (usersWaitingFor1RoundMatchWithAnotherUser.contains(User.getUserByUserna
}

public synchronized static void startMatchWithAnotherUser(String username, String opponentUsername, int rounds) {
if (rounds == 1)
boolean result = true;
if (rounds == 1) {
if (usersWaitingFor1RoundMatchWithAnotherUser.contains(User.getUserByUsername(username)))
usersWaitingFor1RoundMatchWithAnotherUser.remove(User.getUserByUsername(username));
else
usersWaitingFor3RoundMatchWithAnotherUser.remove(User.getUserByUsername(username));
else result = false;
}
else {
if (usersWaitingFor3RoundMatchWithAnotherUser.contains(User.getUserByUsername(username)))
usersWaitingFor3RoundMatchWithAnotherUser.remove(User.getUserByUsername(username));
else result = false;
}

int rand = new Random().nextInt(2);
if (rand == 0) {
GameController gameController = new GameController(username, opponentUsername, rounds);
gameController.createNewGame();
startUserCoinTossMenu(User.getUserByUsername(username), opponentUsername, true);
startLobbyUserCoinTossMenu(User.getUserByUsername(opponentUsername), username, false);
if (result) {
int rand = new Random().nextInt(2);
if (rand == 0) {
GameController gameController = new GameController(username, opponentUsername, rounds);
gameController.createNewGame();
startUserCoinTossMenu(User.getUserByUsername(username), opponentUsername, true);
startLobbyUserCoinTossMenu(User.getUserByUsername(opponentUsername), username, false);
} else {
GameController gameController = new GameController(opponentUsername, username, rounds);
gameController.createNewGame();
startUserCoinTossMenu(User.getUserByUsername(username), opponentUsername, false);
startLobbyUserCoinTossMenu(User.getUserByUsername(opponentUsername), username, true);
}
} else {
GameController gameController = new GameController(opponentUsername, username, rounds);
gameController.createNewGame();
startUserCoinTossMenu(User.getUserByUsername(username), opponentUsername, false);
startLobbyUserCoinTossMenu(User.getUserByUsername(opponentUsername), username, true);
ClientUpdateController clientUpdateController = ClientUpdateController.getClientUpdateController(
User.getUserByUsername(opponentUsername));

clientUpdateController.startRefusedMatchView(username);
}
}

Expand All @@ -99,6 +113,8 @@ public synchronized static void makeMatch(User user, int rounds) {
public synchronized static void cancelMakeMatch(User user) {
usersWaitingFor1RoundMatch.remove(user);
usersWaitingFor3RoundMatch.remove(user);
usersWaitingFor1RoundMatchWithAnotherUser.remove(user);
usersWaitingFor3RoundMatchWithAnotherUser.remove(user);
}

public static void play3Round() {
Expand Down

0 comments on commit 95e8934

Please sign in to comment.