Skip to content

Commit

Permalink
Merge pull request #22 from tkosman/replays
Browse files Browse the repository at this point in the history
Replay mode implemented.
  • Loading branch information
wyz3r0 authored Jan 31, 2024
2 parents 45c1901 + d4476bc commit 288c552
Show file tree
Hide file tree
Showing 11 changed files with 194 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import shared.enums.MessageType;
import shared.enums.PlayerColors;
import shared.enums.Stone;
import shared.enums.UnusualMove;
import shared.messages.AbstractMessage;
import shared.messages.BoardStateMsg;
import shared.messages.ClientInfoMsg;
Expand All @@ -56,9 +57,10 @@
import shared.messages.MoveNotValidMsg;
import shared.messages.OkMsg;
import shared.messages.PlayerPassedMsg;
import shared.messages.PlayerResignedMsg;
import shared.messages.ResultsNegotiationMsg;

public class MultiplayerGameController {
public class GameController {
private static final int CIRCLE_RADIUS = 15;
private static final int SPACING = 5;
private int GRID_SIZE;
Expand All @@ -71,6 +73,7 @@ public class MultiplayerGameController {
private volatile boolean stoneClicked = false;
private volatile boolean passed = false;
private volatile boolean isNegotiating = false;
private volatile boolean resigned = false;

private volatile int moveCordX;
private volatile int moveCordY;
Expand Down Expand Up @@ -242,7 +245,9 @@ else if (!isNegotiating)
//! 2 IN ########## -> It's NOT my turn so I'm waiting for server to send me info back
receiveInfoFromServer();
}
// else if (!resigned) {

// }
}
}
catch (IOException | ClassNotFoundException e) { e.printStackTrace(); }
Expand Down Expand Up @@ -301,19 +306,19 @@ else if (message.getType() == MessageType.PLAYER_PASSED)
switchTurns();
//TODO: status
}
else if (message.getType() == MessageType.GAME_OVER)
else if (message.getType() == MessageType.PLAYER_RESIGNED)
{
//! probably never happenes
//? Game over
//? we need to print the winner and the reason
GameOverMsg gameOverMsg = (GameOverMsg) message;
PlayerColors winner = gameOverMsg.getWinner();
String description = gameOverMsg.getdescription();
if (winner == client.getGame().getPlayerColor()) {
setStatus("WINNER", Color.GREEN);
resigned = true;

PlayerResignedMsg playerResigned = (PlayerResignedMsg) message;
PlayerColors resignee = playerResigned.playerWhoResigned();
if (resignee == client.getGame().getPlayerColor()) {
setStatus("LOOSER", Color.RED);
}
else {
setStatus("LOOSER", Color.RED);
setStatus("WINNER", Color.GREEN);
}
//TODO: close socket
}
Expand Down Expand Up @@ -477,6 +482,7 @@ public void run() {
});

try {
client.closeConnection();
App.setRoot("menu", this, new MenuController());
} catch (IOException ex) {
ex.printStackTrace();
Expand Down Expand Up @@ -734,6 +740,16 @@ else if (passed) {
}
break;
}
else if (resigned) {
System.out.println("resigned");

try {
client.sendMessage(new MoveMsg(UnusualMove.RESIGN));
} catch (IOException e) {
e.printStackTrace();
}
break;
}
}
}

Expand Down Expand Up @@ -765,7 +781,7 @@ protected void setBoard(Stone[][] state) {
}


public MultiplayerGameController(Client client, GameMode gameMode) {
public GameController(Client client, GameMode gameMode) {
this.gameMode = gameMode;
this.client = client;
}
Expand Down Expand Up @@ -829,7 +845,9 @@ void exit() {
@FXML
void resign() {
// TODO: ofer resignation to oponent

if (isMyTurn()) {
resigned = true;
}
// resoultAlert();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ public void run() {

if (!alert.getResult().equals(ButtonType.CANCEL)) {
try {
App.setRoot("game", this, new MultiplayerGameController(this.client, GameMode.MULTI_PLAYER));
App.setRoot("game", this, new GameController(this.client, GameMode.MULTI_PLAYER));
} catch (IOException ex) {
ex.printStackTrace();
}
Expand Down Expand Up @@ -269,7 +269,7 @@ public void run() {

getClient().setGame(new Game(bs, gameJoinedMsg.getGameID(), gameJoinedMsg.getPlayerColors()));

App.setRoot("game", this, new MultiplayerGameController(this.client, GameMode.BOT));
App.setRoot("game", this, new GameController(this.client, GameMode.BOT));
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
}
Expand Down
Loading

0 comments on commit 288c552

Please sign in to comment.