diff --git a/OOP_2B1_Project/src/Main.java b/OOP_2B1_Project/src/Main.java index 68d3915..e7b754b 100644 --- a/OOP_2B1_Project/src/Main.java +++ b/OOP_2B1_Project/src/Main.java @@ -16,7 +16,7 @@ public class Main { // launches graphical interface : MyInterface mjf = new MyInterface(); - mjf.introduction(); +// mjf.introduction(); mjf.setVisible(true); } diff --git a/OOP_2B1_Project/src/backend/Bishop.java b/OOP_2B1_Project/src/backend/Bishop.java index 0db016f..ee99364 100644 --- a/OOP_2B1_Project/src/backend/Bishop.java +++ b/OOP_2B1_Project/src/backend/Bishop.java @@ -14,7 +14,7 @@ public class Bishop extends Piece { return getPossibleMoves(board, null); } - @Override + public ArrayList> getPossibleMoves(ArrayList> board, Move lastMove) { ArrayList> moves = new ArrayList<>();; diff --git a/OOP_2B1_Project/src/backend/Board.java b/OOP_2B1_Project/src/backend/Board.java index 4001626..e7aae1f 100644 --- a/OOP_2B1_Project/src/backend/Board.java +++ b/OOP_2B1_Project/src/backend/Board.java @@ -20,6 +20,7 @@ public class Board { private ArrayList> possibleMoves = new ArrayList<>(); private LinkedList boardHistory = new LinkedList<>(); public boolean timerSwitch = false; + public boolean timerStart = true; public Board(int colNum, int lineNum) { this.width = colNum; @@ -214,6 +215,7 @@ public class Board { public void userTouch(int x, int y) { if ((this.select == false && board.get(y).get(x) != null && this.board.get(y).get(x).isWhite() == turnColor) || (select == true && board.get(y).get(x) != null && board.get(y).get(x).isWhite() == board.get(ym).get(xm).isWhite())) { + timerStart = false; this.xm = x; this.ym = y; select = true; @@ -407,7 +409,10 @@ public class Board { public void setTimerSwitch(boolean timerSwitch) { this.timerSwitch = timerSwitch; } - + + public boolean getTimerStart() { + return timerStart; + } } ///// diff --git a/OOP_2B1_Project/src/backend/Game.java b/OOP_2B1_Project/src/backend/Game.java index 8ad525c..1885f05 100644 --- a/OOP_2B1_Project/src/backend/Game.java +++ b/OOP_2B1_Project/src/backend/Game.java @@ -65,6 +65,9 @@ public class Game extends Thread { System.out.println("Click out of bounds"); return; } + if (board.getTimerStart()) { + mjf.startTimer(board.isTurnColor()); + } if(!isAITurn()) { if (aiPlayer.getAllLegalMoves(board.getBoard(), board.isTurnWhite(),board.getLastMove()).size() != 0){ board.userTouch(x, y); diff --git a/OOP_2B1_Project/src/backend/King.java b/OOP_2B1_Project/src/backend/King.java index 206af62..34801cc 100644 --- a/OOP_2B1_Project/src/backend/King.java +++ b/OOP_2B1_Project/src/backend/King.java @@ -14,7 +14,7 @@ public class King extends Piece { return getPossibleMoves(board, null); } - @Override + public ArrayList> getPossibleMoves(ArrayList> board, Move lastMove) { ArrayList> moves = new ArrayList<>(); diff --git a/OOP_2B1_Project/src/backend/Queen.java b/OOP_2B1_Project/src/backend/Queen.java index 1ccb5d3..6b8d48b 100644 --- a/OOP_2B1_Project/src/backend/Queen.java +++ b/OOP_2B1_Project/src/backend/Queen.java @@ -14,7 +14,7 @@ public class Queen extends Piece { return getPossibleMoves(board, null); } - @Override + public ArrayList> getPossibleMoves(ArrayList> board, Move lastMove) { ArrayList> moves = new ArrayList<>(); diff --git a/OOP_2B1_Project/src/backend/Rook.java b/OOP_2B1_Project/src/backend/Rook.java index 939b647..373a712 100644 --- a/OOP_2B1_Project/src/backend/Rook.java +++ b/OOP_2B1_Project/src/backend/Rook.java @@ -14,7 +14,7 @@ public class Rook extends Piece { return getPossibleMoves(board, null); } - @Override + public ArrayList> getPossibleMoves(ArrayList> board, Move lastMove) { ArrayList> moves = new ArrayList<>(); diff --git a/OOP_2B1_Project/src/windowInterface/JPanelChessBoard.java b/OOP_2B1_Project/src/windowInterface/JPanelChessBoard.java index be8fe4e..260f5cb 100644 --- a/OOP_2B1_Project/src/windowInterface/JPanelChessBoard.java +++ b/OOP_2B1_Project/src/windowInterface/JPanelChessBoard.java @@ -10,6 +10,7 @@ import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; +import javax.swing.ImageIcon; import javax.swing.JPanel; import backend.Game; @@ -30,6 +31,8 @@ public class JPanelChessBoard extends JPanel { private boolean selectedPieceIsWhite; private PieceType selectedPieceType; private boolean pieceAdderMode; + private Image backgroundImage; + public JPanelChessBoard(MyInterface itf) { super(); @@ -38,6 +41,7 @@ public class JPanelChessBoard extends JPanel { selectedPieceIsWhite = true; selectedPieceType = PieceType.Pawn; pieceSelectorMode = false; + backgroundImage = new ImageIcon(getClass().getResource("image_OOP.png")).getImage(); try { spriteSheet = ImageIO.read(new File("pieces/newPieces.png")); @@ -81,7 +85,8 @@ public class JPanelChessBoard extends JPanel { @Override protected void paintComponent(Graphics g) { super.paintComponent(g); - this.setBackground(new Color(238,236,208)); + g.drawImage(backgroundImage, 0, 0, getWidth(), getHeight(), this); +// this.setBackground(new Color(238,236,208)); if(pieceSelectorMode) { g.drawImage( spriteSheet, @@ -95,6 +100,9 @@ public class JPanelChessBoard extends JPanel { } if (myGame != null) { // Draw Interface from state of simulator + g.setColor(new Color(238, 236, 208)); // Your default color + g.fillRect(0, 0, getWidth()+1, getHeight()+1); + repaint(); float cellWidth = cellWidth(); float cellHeight = cellHeight(); @@ -141,6 +149,22 @@ public class JPanelChessBoard extends JPanel { for (Piece piece : myGame.getPieces()) { drawPiece(g,piece); } + g.setColor(Color.BLACK); + + + for (int x = 0; x < myGame.getWidth(); x++) { + char letter = (char) ('a' + x); + int xLetter = Math.round(x * cellWidth() + cellWidth() / 2) - 4; + int yLetter = getHeight() - 5; + g.drawString(String.valueOf(letter), xLetter, yLetter); + } + + for (int y = 0; y < myGame.getHeight(); y++) { + int number = myGame.getHeight() - y; + int xNumber = 5; + int yNumber = Math.round(y * cellHeight() + cellHeight() / 2) + 5; + g.drawString(String.valueOf(number), xNumber, yNumber); + } } } diff --git a/OOP_2B1_Project/src/windowInterface/MyInterface.java b/OOP_2B1_Project/src/windowInterface/MyInterface.java index f7185c0..6d32ca3 100644 --- a/OOP_2B1_Project/src/windowInterface/MyInterface.java +++ b/OOP_2B1_Project/src/windowInterface/MyInterface.java @@ -51,12 +51,20 @@ public class MyInterface extends JFrame { private JLabel whiteTimerLabel; private JLabel blackTimerLabel; public TimerManager timerManager; + + + /** * Create the frame. */ public MyInterface() { + + + + + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - setBounds(10, 10, 650, 650); + setBounds(10, 10, 800, 800); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); contentPane.setLayout(new BorderLayout(0, 0)); @@ -180,8 +188,7 @@ public class MyInterface extends JFrame { game.setDefaultSetup(); if (timerManager == null) timerManager = new TimerManager(whiteTimerLabel, blackTimerLabel, () -> gameOverByTimeout(), time); - timerManager.reset(); - timerManager.start(true); // white starts + timerManager.reset(time); } public void clickButtonAdder() { panelDraw.toggleAdderMode(); @@ -236,8 +243,8 @@ public class MyInterface extends JFrame { game.setAutoPlayerDepth(depth); if (timerManager == null) timerManager = new TimerManager(whiteTimerLabel, blackTimerLabel, () -> gameOverByTimeout(), time); - timerManager.reset(); - timerManager.start(game.getTurnColor()); + timerManager.reset(time); +// timerManager.start(game.getTurnColor()); game.start(); // this.repaint(); // update(game.getTurnNumber(), game.getTurnColor()); @@ -296,11 +303,28 @@ public class MyInterface extends JFrame { } public void showGameOverMessage(String message) { - JOptionPane.showMessageDialog(this, message, "Game Over", JOptionPane.INFORMATION_MESSAGE); - game.toggleAI(false); + game.toggleAI(false); game.toggleAI(true); chckbxWhiteAI.setSelected(false); chckbxBlackAI.setSelected(false); + Object[] options = {"YES", "NO", "Start a new game"}; + int choice = JOptionPane.showOptionDialog(this, "GAME OVER \nDo you want to exit? ", + "Game Over", + JOptionPane.DEFAULT_OPTION, + JOptionPane.QUESTION_MESSAGE, + null, + options, + options[1] // default: NO + ); + switch (choice) { + case 0: System.exit(0); // exit + case 1: ; + case 2: clicButtonStart(); + break; + default: ; + + } + } private int askDifficulty() { @@ -327,8 +351,8 @@ public class MyInterface extends JFrame { Object[] options = {"1 min", "2 Min", "5 Min", "10 Min"}; int choice = JOptionPane.showOptionDialog( this, - "Select Difficulty Level:", - "Difficulty", + "Select the duration of the game:", + "Duration", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, @@ -376,7 +400,10 @@ public class MyInterface extends JFrame { return 1; } - + + public void startTimer(boolean isWhite) { + timerManager.start(isWhite); + } public void gameOverByTimeout() { diff --git a/OOP_2B1_Project/src/windowInterface/TimerManager.java b/OOP_2B1_Project/src/windowInterface/TimerManager.java index bd2cab6..de66404 100644 --- a/OOP_2B1_Project/src/windowInterface/TimerManager.java +++ b/OOP_2B1_Project/src/windowInterface/TimerManager.java @@ -60,7 +60,9 @@ public class TimerManager { timer.stop(); } -public void reset() { +public void reset(int time) { + whiteSeconds = time; + blackSeconds = time; updateLabel(whiteLabel, whiteSeconds); updateLabel(blackLabel, blackSeconds); } diff --git a/OOP_2B1_Project/image_OOP.png b/OOP_2B1_Project/src/windowInterface/image_OOP.png similarity index 100% rename from OOP_2B1_Project/image_OOP.png rename to OOP_2B1_Project/src/windowInterface/image_OOP.png