Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added recordings/REC_Player_vs_CPU_1768350437773.dat
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static ServerConnectionManager getInstance() {
public void connect(String host, int port ) throws IOException {
isIntentionalDisconnect = false;
InetAddress ip = InetAddress.getByName("localhost");
socket = new Socket(ip, port);
socket = new Socket(host, port);
dis = new DataInputStream(socket.getInputStream());
dos = new DataOutputStream(socket.getOutputStream());
Thread th = new Thread(this::readMessages);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ private void handleOfflinePve(int row, int col) {
if (checkGameEnd()) {
return;
}

updateTurnIndicator();
scheduleAiTurn();
}

Expand All @@ -325,6 +325,7 @@ private void handleOnlinePvp(int row, int col) {
private void performMove(int row, int col, char player) {
gameBoard.makeMove(row, col, player);
updateCell(row, col, player);

}

private void scheduleAiTurn() {
Expand All @@ -339,13 +340,12 @@ private void executeAiMove() {
Move aiMove = gameService.getNextMove(gameBoard, GameBoard.PLAYER_O);

if (aiMove != null) {

performMove(aiMove.getRow(), aiMove.getCol(), GameBoard.PLAYER_O);
}

if (!checkGameEnd()) {
enableBoard();
updateTurnIndicator();
enableBoard();
}
}

Expand Down Expand Up @@ -378,21 +378,26 @@ private void updateCell(int row, int col, char player) {

private void updateTurnIndicator() {
char currentPlayer = gameBoard.getCurrentPlayer();

if (currentPlayer == GameBoard.PLAYER_X) {
setActiveCard(playerCard, opponentCard);
}
else {
setActiveCard(opponentCard, playerCard);
}
if (gameMode == GameMode.OFFLINE_PVP || gameMode == GameMode.OFFLINE_PVE || gameMode == GameMode.REPLAY) {
if (localPlayerId == GameBoard.PLAYER_X) {

switch (gameMode) {

case ONLINE_PVP -> {
if (currentPlayer == localPlayerId) {
setActiveCard(playerCard, opponentCard);
} else {
setActiveCard(opponentCard, playerCard);
}
}

case OFFLINE_PVP, OFFLINE_PVE, REPLAY -> {
if (currentPlayer == GameBoard.PLAYER_X) {
setActiveCard(playerCard, opponentCard);
} else {
setActiveCard(opponentCard, playerCard);
}
}
}
}

private void setActiveCard(VBox activeCard, VBox inactiveCard) {
activeCard.getStyleClass().add("active-card");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void initialize(URL location, ResourceBundle resources) {
});

serverPresets.put("Local Server", "127.0.0.1");
serverPresets.put("Network Server", "192.168.1.3");
serverPresets.put("Network Server", "10.145.0.124");

ipComboBox.getItems().addAll(serverPresets.keySet());
ipComboBox.getSelectionModel().select("Local Server");
Expand Down