diff --git a/.idea/copilotDiffState.xml b/.idea/copilotDiffState.xml
index e3a4679..40e10bf 100644
--- a/.idea/copilotDiffState.xml
+++ b/.idea/copilotDiffState.xml
@@ -20,6 +20,41 @@
+pantalla_emparejamiento
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/main/java/es/iesquevedo/controller/GameController.java b/src/main/java/es/iesquevedo/controller/GameController.java
index 24b1b19..bb92515 100644
--- a/src/main/java/es/iesquevedo/controller/GameController.java
+++ b/src/main/java/es/iesquevedo/controller/GameController.java
@@ -312,6 +312,13 @@ private void onBoardClick(MouseEvent event) {
}
}
+ public void initGame(String gameId, String playerName) {
+ this.player1Name = playerName + " (Negro)";
+ this.player2Name = "Oponente (Blanco)";
+ updatePlayerInfo();
+ LOGGER.log(Level.INFO, "Partida iniciada - GameID: " + gameId + " - Jugador: " + playerName);
+ }
+
private boolean isValidPosition(int row, int col) {
return row >= 0 && row < BOARD_SIZE && col >= 0 && col < BOARD_SIZE;
}
diff --git a/src/main/java/es/iesquevedo/ui/MatchingScreenController.java b/src/main/java/es/iesquevedo/ui/MatchingScreenController.java
new file mode 100644
index 0000000..9bdb5bf
--- /dev/null
+++ b/src/main/java/es/iesquevedo/ui/MatchingScreenController.java
@@ -0,0 +1,159 @@
+package es.iesquevedo.ui;
+
+import es.iesquevedo.controller.GameController;
+import es.iesquevedo.model.Game;
+import es.iesquevedo.model.Player;
+import es.iesquevedo.service.GameService;
+import javafx.application.Platform;
+import javafx.fxml.FXML;
+import javafx.fxml.FXMLLoader;
+import javafx.scene.Parent;
+import javafx.scene.Scene;
+import javafx.scene.control.Button;
+import javafx.scene.control.Label;
+import javafx.stage.Stage;
+
+import java.io.IOException;
+import java.util.Timer;
+import java.util.TimerTask;
+import java.util.concurrent.CompletableFuture;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+public class MatchingScreenController {
+
+ private static final Logger LOGGER = Logger.getLogger(MatchingScreenController.class.getName());
+
+ @FXML
+ private Label statusLabel;
+
+ @FXML
+ private Label timeLabel;
+
+ @FXML
+ private Button cancelButton;
+
+ private GameService gameService;
+ private Player currentPlayer;
+ private Timer timer;
+ private int elapsedSeconds = 0;
+ private CompletableFuture currentSearch;
+ private volatile boolean searching = true;
+
+ public void setGameService(GameService gameService) {
+ this.gameService = gameService;
+ }
+
+ public void startMatching(Player player) {
+ this.currentPlayer = player;
+ startTimer();
+ startSearch();
+ }
+
+ private void startTimer() {
+ timer = new Timer(true);
+ timer.scheduleAtFixedRate(new TimerTask() {
+ @Override
+ public void run() {
+ Platform.runLater(() -> {
+ elapsedSeconds++;
+ timeLabel.setText("Tiempo de espera: " + elapsedSeconds + "s");
+ });
+ }
+ }, 1000, 1000);
+ }
+
+ private void startSearch() {
+ statusLabel.setText("Buscando jugador disponible...");
+
+ currentSearch = CompletableFuture.supplyAsync(() -> {
+ try {
+ int waitTime = 3000 + (int)(Math.random() * 5000);
+ Thread.sleep(waitTime);
+ if (!searching) return null;
+
+ String gameName = "Partida_" + System.currentTimeMillis();
+ return gameService.createGame(gameName, currentPlayer);
+ } catch (Exception e) {
+ LOGGER.log(Level.WARNING, "Search interrupted", e);
+ return null;
+ }
+ });
+
+ currentSearch.thenAccept(game -> {
+ if (game != null && searching) {
+ Platform.runLater(() -> {
+ stopTimer();
+ statusLabel.setText("¡Oponente encontrado!");
+ navigateToGame(game.getId());
+ });
+ }
+ }).exceptionally(ex -> {
+ Platform.runLater(() -> {
+ if (searching) {
+ statusLabel.setText("Error en la búsqueda. Intenta de nuevo.");
+ cancelButton.setText("Volver");
+ }
+ });
+ return null;
+ });
+ }
+
+ private void navigateToGame(String gameId) {
+ try {
+ searching = false;
+ if (currentSearch != null) {
+ currentSearch.cancel(true);
+ }
+
+ FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/Game.fxml"));
+ Parent root = loader.load();
+
+ GameController gameController = loader.getController();
+ String playerName = currentPlayer != null ? currentPlayer.getName() : "Jugador";
+ gameController.initGame(gameId, playerName);
+
+ Stage stage = (Stage) cancelButton.getScene().getWindow();
+ stage.setScene(new Scene(root, 900, 700));
+ stage.setTitle("InazumaGo - Partida: " + gameId);
+ stage.show();
+
+ } catch (IOException e) {
+ LOGGER.log(Level.SEVERE, "Error loading game screen", e);
+ statusLabel.setText("Error al cargar la partida");
+ }
+ }
+
+ @FXML
+ private void onCancel() {
+ searching = false;
+ if (currentSearch != null) {
+ currentSearch.cancel(true);
+ }
+ stopTimer();
+ goBackToMainMenu();
+ }
+
+ private void goBackToMainMenu() {
+ try {
+ FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/MainScreen.fxml"));
+ Parent root = loader.load();
+
+ // Just load the main screen - no additional setup needed
+ Stage stage = (Stage) cancelButton.getScene().getWindow();
+ stage.setScene(new Scene(root, 700, 500));
+ stage.setTitle("InazumaGo - Pantalla Principal");
+ stage.show();
+
+ } catch (IOException e) {
+ LOGGER.log(Level.SEVERE, "Error returning to main menu", e);
+ }
+ }
+
+ private void stopTimer() {
+ if (timer != null) {
+ timer.cancel();
+ timer = null;
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/main/resources/fxml/MatchingScreen.fxml b/src/main/resources/fxml/MatchingScreen.fxml
new file mode 100644
index 0000000..0b88457
--- /dev/null
+++ b/src/main/resources/fxml/MatchingScreen.fxml
@@ -0,0 +1,26 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file