public void back() { rightPanel.getBlackCheckers().setText((game.getBlackPlayer().eatenCheckers())); rightPanel.getWhiteCheckers().setText((game.getWhitePlayer().eatenCheckers())); if (game.getTurn() == 1) { rightPanel.getNames().setText("White Turn"); } else { rightPanel.getNames().setText("Black Turn"); } for (int i = 0; i < tem.length; i++) { for (int j = 0; j < tem[i].length; j++) { tem[i][j].setClicked(false); tem[i][j].setHighlighted(false); CheckerButton.setOneButtonClicked(false); tem[i][j].validate(); tem[i][j].repaint(); gamePanel.remove(tem[i][j]); rightPanel.validate(); rightPanel.repaint(); this.validate(); this.repaint(); } } }
@Override public void mouseClicked(MouseEvent arg0) { Object temo = arg0.getSource(); Point start = ((CheckerButton) temo).getPosition(); if (game.getTurn() == game.getColor(new Point(start.getY(), start.getX()))) { if (firstHit) { ArrayList<Point> possibleMoves = game.getPossibleMoves(new Point(start.getY(), start.getX())); clickedPoint = start; CheckerButton.setOneButtonClicked(!CheckerButton.isOneButtonClicked()); perform(possibleMoves, start); firstHit = !firstHit; return; } else { if (clickedPoint.compareTo(start) == 0) { deSelect(start); return; } } } else { if (game.move( new Point(clickedPoint.getY(), clickedPoint.getX()), new Point(start.getY(), start.getX()))) { back(); tem = new CheckerButton[8][8]; updateBoard(); if (game.isGameOver()) { if (game.getWinner() == 1) { JOptionPane.showMessageDialog( null, game.getWhitePlayer().getName() + " Wins !!", "Congratulations", JOptionPane.PLAIN_MESSAGE); } else { JOptionPane.showMessageDialog( null, game.getBlackPlayer().getName() + " Wins !!", "Congratulations", JOptionPane.PLAIN_MESSAGE); } int x = JOptionPane.showConfirmDialog( null, "Do you want to play again ??", "Confirmation Message", 0); if (x == 0) { this.setVisible(false); restart.setVisible(true); } else { System.exit(0); } } } } }