diff --git a/app/src/main/java/chess/view/simplerender/Window.java b/app/src/main/java/chess/view/simplerender/Window.java index 75637fe..2ace41e 100644 --- a/app/src/main/java/chess/view/simplerender/Window.java +++ b/app/src/main/java/chess/view/simplerender/Window.java @@ -7,7 +7,6 @@ import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.io.IOException; import java.util.List; -import java.util.Random; import javax.swing.JButton; import javax.swing.JFrame; @@ -22,12 +21,11 @@ import chess.controller.CommandExecutor; import chess.controller.commands.CastlingCommand; import chess.controller.commands.GetAllowedMovesPieceCommand; import chess.controller.commands.GetPieceAtCommand; -import chess.controller.commands.GetPlayerMovesCommand; import chess.controller.commands.MoveCommand; import chess.controller.commands.PromoteCommand; import chess.controller.commands.PromoteCommand.PromoteType; -import chess.controller.event.GameListener; import chess.controller.commands.UndoCommand; +import chess.controller.event.GameListener; import chess.model.Coordinate; import chess.model.Move; import chess.model.Piece; @@ -231,6 +229,7 @@ public class Window extends JFrame implements GameListener { public void patSituation() { SwingUtilities.invokeLater(() -> { JOptionPane.showMessageDialog(this, "Pat. It's a draw!"); + this.dispose(); }); } @@ -248,39 +247,41 @@ public class Window extends JFrame implements GameListener { @Override public void promotePawn(Coordinate pieceCoords) { - // SwingUtilities.invokeLater(() -> { - // String result = null; + if (!showPopups) + return; + SwingUtilities.invokeLater(() -> { + String result = null; - // Object[] possibilities = new Object[PromoteType.values().length]; - // int i = 0; - // for (PromoteType type : PromoteType.values()) { - // possibilities[i] = type.name(); - // i++; - // } + Object[] possibilities = new Object[PromoteType.values().length]; + int i = 0; + for (PromoteType type : PromoteType.values()) { + possibilities[i] = type.name(); + i++; + } - // while (result == null || result.isEmpty()) { - // result = (String) JOptionPane.showInputDialog( - // this, - // "Choose the type of piece to upgrade the pawn", - // "Promote Dialog", - // JOptionPane.PLAIN_MESSAGE, - // null, - // possibilities, - // possibilities[0]); - // } + while (result == null || result.isEmpty()) { + result = (String) JOptionPane.showInputDialog( + this, + "Choose the type of piece to upgrade the pawn", + "Promote Dialog", + JOptionPane.PLAIN_MESSAGE, + null, + possibilities, + possibilities[0]); + } - // PromoteType choosedType = null; + PromoteType choosedType = null; - // for (PromoteType type : PromoteType.values()) { - // if (type.name().equals(result)) { - // choosedType = type; - // break; - // } - // } + for (PromoteType type : PromoteType.values()) { + if (type.name().equals(result)) { + choosedType = type; + break; + } + } - // if (choosedType != null) - // sendCommand(new PromoteCommand(choosedType)); - // }); + if (choosedType != null) + sendCommand(new PromoteCommand(choosedType)); + }); } @Override