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
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ public void sendGameRequest(String targetPlayerId) {
}

public void sendGameResponse(GameRequestInfo originalRequest, boolean accepted) {
setWaiting(false);

AuthResponseEntity me = connection.getPlayer();

GameResponseInfo responseInfo = new GameResponseInfo(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package com.boredxgames.tictactoeclient.domain.services.game;

import com.boredxgames.tictactoeclient.domain.managers.navigation.NavigationAction;
import com.boredxgames.tictactoeclient.domain.managers.navigation.NavigationManager;
import com.boredxgames.tictactoeclient.domain.managers.navigation.Screens;
import com.boredxgames.tictactoeclient.domain.model.*;
import com.boredxgames.tictactoeclient.domain.network.ServerConnectionManager;
import com.boredxgames.tictactoeclient.domain.services.GameService;
Expand Down Expand Up @@ -79,19 +76,19 @@ public void makeMove(Move move, char currentPlayer) {
}

public void sendGameEnd(String winnerId) {
ServerConnectionManager connectionManager = ServerConnectionManager.getInstance();
ServerConnectionManager connectionManager = ServerConnectionManager.getInstance();

if (OnlineGameState.info == null) return;

String roomId = OnlineGameState.info.getRoomId();
GameEndInfo endInfo = new GameEndInfo(roomId, winnerId);

Message msg = Message.createMessage(
MessageType.RESPONSE,
Action.GAME_END,
endInfo
);

System.out.println("rafaaaaaaaaaaaat"+msg);
connectionManager.sendMessage(msg);
}
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,20 @@
import com.boredxgames.tictactoeclient.domain.managers.navigation.Screens;
import com.boredxgames.tictactoeclient.domain.model.GameMode;
import com.boredxgames.tictactoeclient.domain.model.GameNavigationParams;

import com.boredxgames.tictactoeclient.domain.model.GameRecord;
import com.boredxgames.tictactoeclient.domain.model.GameState;
import com.boredxgames.tictactoeclient.domain.model.Move;
import com.boredxgames.tictactoeclient.domain.model.OnlineGameState;
import com.boredxgames.tictactoeclient.domain.services.GameService;
import com.boredxgames.tictactoeclient.domain.services.communication.MessageRouter;
import com.boredxgames.tictactoeclient.domain.services.game.GameBoard;
import com.boredxgames.tictactoeclient.domain.services.game.OfflinePVEAIService;
import com.boredxgames.tictactoeclient.domain.services.game.OfflinePVPService;
import com.boredxgames.tictactoeclient.domain.services.game.OnlinePVPService;
import com.boredxgames.tictactoeclient.domain.model.GameRecord;
import com.boredxgames.tictactoeclient.domain.model.OnlineGameState;
import com.boredxgames.tictactoeclient.domain.services.communication.MessageRouter;
import com.boredxgames.tictactoeclient.domain.services.storage.GameRecordingService;

import java.net.URL;
import java.util.Objects;
import java.util.ResourceBundle;

import javafx.animation.KeyFrame;
import javafx.animation.PauseTransition;
import javafx.animation.Timeline;
Expand All @@ -47,33 +44,56 @@ public class GameController implements Initializable, NavigationParameterAware {

public GridPane gameGrid;

@FXML private Button backButton;
@FXML private Button settingsButton;
@FXML private HBox difficultyBadge;
@FXML private Label difficultyLabel;

@FXML private VBox playerCard;
@FXML private VBox opponentCard;
@FXML private Label playerNameLabel;
@FXML private Label opponentNameLabel;
@FXML private Label playerScoreLabel;
@FXML private Label opponentScoreLabel;
@FXML private Label opponentTypeLabel;

@FXML private Button cell00, cell01, cell02;
@FXML private Button cell10, cell11, cell12;
@FXML private Button cell20, cell21, cell22;
@FXML
private Button backButton;
@FXML
private Button settingsButton;
@FXML
private HBox difficultyBadge;
@FXML
private Label difficultyLabel;

@FXML
private VBox playerCard;
@FXML
private VBox opponentCard;
@FXML
private Label playerNameLabel;
@FXML
private Label opponentNameLabel;
@FXML
private Label playerScoreLabel;
@FXML
private Label opponentScoreLabel;
@FXML
private Label opponentTypeLabel;

@FXML
private Button cell00, cell01, cell02;
@FXML
private Button cell10, cell11, cell12;
@FXML
private Button cell20, cell21, cell22;
private Button[][] cells;

@FXML private StackPane modalOverlay;
@FXML private Text modalIcon;
@FXML private Label modalTitle;
@FXML private Label modalMessage;
@FXML private MediaView victoryVideo;
@FXML private Button playAgainButton;
@FXML private Button changeDifficultyButton;
@FXML private Button mainMenuButton;
@FXML private Button saveGameButton;
@FXML
private StackPane modalOverlay;
@FXML
private Text modalIcon;
@FXML
private Label modalTitle;
@FXML
private Label modalMessage;
@FXML
private MediaView victoryVideo;
@FXML
private Button playAgainButton;
@FXML
private Button changeDifficultyButton;
@FXML
private Button mainMenuButton;
@FXML
private Button saveGameButton;

private GameBoard gameBoard;
private GameMode gameMode;
Expand All @@ -93,9 +113,9 @@ public class GameController implements Initializable, NavigationParameterAware {
@Override
public void initialize(URL url, ResourceBundle rb) {
cells = new Button[][]{
{cell00, cell01, cell02},
{cell10, cell11, cell12},
{cell20, cell21, cell22}
{cell00, cell01, cell02},
{cell10, cell11, cell12},
{cell20, cell21, cell22}
};
gameBoard = new GameBoard();
setupCellHandlers();
Expand Down Expand Up @@ -230,13 +250,12 @@ private void setupButtonHandlers() {
playAgainButton.setOnAction(e -> resetGame());

mainMenuButton.setOnAction(e -> {
if(gameMode == GameMode.OFFLINE_PVE || gameMode == GameMode.OFFLINE_PVP) {
if (gameMode == GameMode.OFFLINE_PVE || gameMode == GameMode.OFFLINE_PVP) {
NavigationManager.navigate(Screens.GAME_MODE, NavigationAction.REPLACE_ALL);
} else {
NavigationManager.navigate(Screens.Home, NavigationAction.REPLACE_ALL);
}
});

});

backButton.setOnAction(e -> {
if (gameMode == GameMode.OFFLINE_PVE || gameMode == GameMode.OFFLINE_PVP) {
Expand Down Expand Up @@ -274,17 +293,24 @@ private void handleSaveGame() {
}

private void handleCellClick(int row, int col) {
if (!gameBoard.isValidMove(row, col)) return;
if (gameMode == GameMode.REPLAY) return;
if (!gameBoard.isValidMove(row, col)) {
return;
}
if (gameMode == GameMode.REPLAY) {
return;
}

if (gameMode == GameMode.ONLINE_PVP && gameBoard.getCurrentPlayer() != localPlayerId) {
return;
}

switch (gameMode) {
case OFFLINE_PVP -> handleOfflinePvp(row, col);
case OFFLINE_PVE -> handleOfflinePve(row, col);
case ONLINE_PVP -> handleOnlinePvp(row, col);
case OFFLINE_PVP ->
handleOfflinePvp(row, col);
case OFFLINE_PVE ->
handleOfflinePve(row, col);
case ONLINE_PVP ->
handleOnlinePvp(row, col);
}
}

Expand Down Expand Up @@ -346,7 +372,8 @@ private void executeAiMove() {

if (!checkGameEnd()) {

updateTurnIndicator();enableBoard();
updateTurnIndicator();
enableBoard();
}
}

Expand Down Expand Up @@ -377,25 +404,25 @@ private void updateCell(int row, int col, char player) {
private void updateTurnIndicator() {
char currentPlayer = gameBoard.getCurrentPlayer();

switch (gameMode) {
switch (gameMode) {

case ONLINE_PVP -> {
if (currentPlayer == localPlayerId) {
setActiveCard(playerCard, opponentCard);
} else {
setActiveCard(opponentCard, playerCard);
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);
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 All @@ -415,8 +442,11 @@ private void handleGameEnd() {
}

char winnerChar = GameBoard.EMPTY;
if (state == GameState.X_WINS) winnerChar = GameBoard.PLAYER_X;
else if (state == GameState.O_WINS) winnerChar = GameBoard.PLAYER_O;
if (state == GameState.X_WINS) {
winnerChar = GameBoard.PLAYER_X;
} else if (state == GameState.O_WINS) {
winnerChar = GameBoard.PLAYER_O;
}

if (gameMode != GameMode.REPLAY) {
if (winnerChar == GameBoard.PLAYER_X) {
Expand All @@ -431,7 +461,13 @@ private void handleGameEnd() {
String videoToPlay = "draw";

if (state == GameState.DRAW) {
videoToPlay = "draw";
{
videoToPlay = "draw";
if (gameMode == GameMode.ONLINE_PVP) {
OnlinePVPService.getInstance().sendGameEnd(null);
}
}

} else if (gameMode == GameMode.ONLINE_PVP) {
boolean amIWinner = (winnerChar == localPlayerId);
videoToPlay = amIWinner ? "victory" : "defeat";
Expand All @@ -441,17 +477,20 @@ private void handleGameEnd() {
winnerId = OnlineGameState.info.getPlayer1();
} else if (state == GameState.O_WINS) {
winnerId = OnlineGameState.info.getPlayer2();
} else {
winnerId = null;
}
System.out.println("sending sendgin " + winnerId);
OnlinePVPService.getInstance().sendGameEnd(winnerId);
} else {
videoToPlay = (winnerChar == GameBoard.PLAYER_X) ? "victory" : "defeat";
}

playVictoryVideo(videoToPlay);

PauseTransition pause = new PauseTransition(Duration.millis(800));
pause.setOnFinished(e -> showGameOverModal(state));
pause.play();
showGameOverModal(state);
// PauseTransition pause = new PauseTransition(Duration.millis(800));
// pause.setOnFinished(e -> showGameOverModal(state));
// pause.play();
}

private void showGameOverModal(GameState state) {
Expand Down Expand Up @@ -572,15 +611,19 @@ public void resetGame() {
private void disableBoard() {
for (int row = 0; row < 3; row++) {
for (int col = 0; col < 3; col++) {
if (gameBoard.getCellValue(row, col) == GameBoard.EMPTY) cells[row][col].setDisable(true);
if (gameBoard.getCellValue(row, col) == GameBoard.EMPTY) {
cells[row][col].setDisable(true);
}
}
}
}

private void enableBoard() {
for (int row = 0; row < 3; row++) {
for (int col = 0; col < 3; col++) {
if (gameBoard.getCellValue(row, col) == GameBoard.EMPTY) cells[row][col].setDisable(false);
if (gameBoard.getCellValue(row, col) == GameBoard.EMPTY) {
cells[row][col].setDisable(false);
}
}
}
}
Expand All @@ -604,4 +647,4 @@ private void startReplay() {
}
timeline.play();
}
}
}
4 changes: 2 additions & 2 deletions src/main/resources/css/features/game_screen.css
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,8 @@
}

.trophy-container {
-fx-background-color: -surface-darker;
-fx-background-radius: 50%;
-fx-background-color: transparent;
-fx-background-radius: 0%;
-fx-padding: 16;
-fx-effect: dropshadow(gaussian, rgba(0, 0, 0, 0.3), 10, 0, 0, 4);
}
Expand Down