Color green + Welcome interface
This commit is contained in:
parent
2ba7cccbf4
commit
9fd3642203
|
|
@ -117,9 +117,6 @@ public class Board {
|
||||||
}
|
}
|
||||||
return pieces;
|
return pieces;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSelected(int x, int y) {
|
public boolean isSelected(int x, int y) {
|
||||||
|
|
@ -127,13 +124,6 @@ public class Board {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void userTouch(int x, int y) {
|
public void userTouch(int x, int y) {
|
||||||
if (x < 0 || x >= width || y < 0 || y >= height) return;
|
if (x < 0 || x >= width || y < 0 || y >= height) return;
|
||||||
|
|
||||||
|
|
@ -171,7 +161,7 @@ public class Board {
|
||||||
board[selectedX][selectedY] = null;
|
board[selectedX][selectedY] = null;
|
||||||
selectedPiece.setX(x);
|
selectedPiece.setX(x);
|
||||||
selectedPiece.setY(y);
|
selectedPiece.setY(y);
|
||||||
selectedPiece.setMoved(true); // ✅ Marque la pièce comme ayant bougé
|
selectedPiece.setMoved(true);
|
||||||
|
|
||||||
|
|
||||||
// Déplacement de la tour si roque
|
// Déplacement de la tour si roque
|
||||||
|
|
|
||||||
|
|
@ -77,10 +77,12 @@ public class JPanelChessBoard extends JPanel {
|
||||||
myGame = simu;
|
myGame = simu;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void paintComponent(Graphics g) {
|
protected void paintComponent(Graphics g) {
|
||||||
super.paintComponent(g);
|
super.paintComponent(g);
|
||||||
this.setBackground(Color.black);
|
this.setBackground(new Color(0, 100, 0)); // Dark green background
|
||||||
|
|
||||||
if(pieceSelectorMode) {
|
if(pieceSelectorMode) {
|
||||||
g.drawImage(
|
g.drawImage(
|
||||||
spriteSheet,
|
spriteSheet,
|
||||||
|
|
@ -92,23 +94,34 @@ public class JPanelChessBoard extends JPanel {
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (myGame != null) {
|
if (myGame != null) {
|
||||||
// Draw Interface from state of simulator
|
// Define green theme colors
|
||||||
|
Color lightGreen = new Color(234, 235, 200); // Light green squares
|
||||||
|
Color darkGreen = new Color(119, 149, 86); // Dark green squares
|
||||||
|
Color highlightYellow = new Color(247, 247, 105); // Highlight color
|
||||||
|
Color selectBlue = new Color(66, 135, 245); // Selection color
|
||||||
|
|
||||||
|
// Draw chess board squares
|
||||||
float cellWidth = cellWidth();
|
float cellWidth = cellWidth();
|
||||||
float cellHeight = cellHeight();
|
float cellHeight = cellHeight();
|
||||||
|
|
||||||
g.setColor(Color.white);
|
|
||||||
for(int x=0; x<myGame.getWidth(); x++) {
|
for(int x=0; x<myGame.getWidth(); x++) {
|
||||||
for (int y=0; y<myGame.getHeight(); y++) {
|
for (int y=0; y<myGame.getHeight(); y++) {
|
||||||
boolean isSelect = myGame.isSelected(x,y);
|
boolean isSelect = myGame.isSelected(x,y);
|
||||||
boolean isHighlight = myGame.isHighlighted(x,y);
|
boolean isHighlight = myGame.isHighlighted(x,y);
|
||||||
|
|
||||||
|
// Set square color
|
||||||
if(isSelect) {
|
if(isSelect) {
|
||||||
g.setColor(Color.blue);
|
g.setColor(selectBlue);
|
||||||
}
|
}
|
||||||
if(isHighlight) {
|
else if(isHighlight) {
|
||||||
g.setColor(Color.yellow);
|
g.setColor(highlightYellow);
|
||||||
}
|
}
|
||||||
if((x+y)%2==1 || isSelect || isHighlight) {
|
else {
|
||||||
|
g.setColor((x + y) % 2 == 0 ? lightGreen : darkGreen);
|
||||||
|
}
|
||||||
|
|
||||||
g.fillRect(
|
g.fillRect(
|
||||||
Math.round(x*cellWidth),
|
Math.round(x*cellWidth),
|
||||||
Math.round(y*cellHeight),
|
Math.round(y*cellHeight),
|
||||||
|
|
@ -116,14 +129,10 @@ public class JPanelChessBoard extends JPanel {
|
||||||
Math.round(cellHeight)
|
Math.round(cellHeight)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if(isHighlight || isSelect) {
|
|
||||||
g.setColor(Color.white);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
// Draw grid lines (optional)
|
||||||
}
|
g.setColor(new Color(0, 80, 0)); // Darker green for grid lines
|
||||||
|
|
||||||
g.setColor(Color.gray);
|
|
||||||
for(int x=0; x<myGame.getWidth(); x++) {
|
for(int x=0; x<myGame.getWidth(); x++) {
|
||||||
int graphX = Math.round(x*cellWidth);
|
int graphX = Math.round(x*cellWidth);
|
||||||
g.drawLine(graphX, 0, graphX, this.getHeight());
|
g.drawLine(graphX, 0, graphX, this.getHeight());
|
||||||
|
|
@ -133,6 +142,7 @@ public class JPanelChessBoard extends JPanel {
|
||||||
g.drawLine(0, graphY, this.getWidth(), graphY);
|
g.drawLine(0, graphY, this.getWidth(), graphY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Draw pieces
|
||||||
for (Piece piece : myGame.getPieces()) {
|
for (Piece piece : myGame.getPieces()) {
|
||||||
drawPiece(g, piece);
|
drawPiece(g, piece);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package windowInterface;
|
package windowInterface;
|
||||||
import java.awt.BorderLayout;
|
import java.awt.BorderLayout;
|
||||||
|
import java.awt.CardLayout;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.GridLayout;
|
import java.awt.GridLayout;
|
||||||
|
|
||||||
|
|
@ -37,11 +38,14 @@ public class MyInterface extends JFrame {
|
||||||
private JLabel turnLabel;
|
private JLabel turnLabel;
|
||||||
private JLabel borderLabel;
|
private JLabel borderLabel;
|
||||||
private JLabel speedLabel;
|
private JLabel speedLabel;
|
||||||
private JPanelChessBoard panelDraw;
|
|
||||||
private Game game;
|
private Game game;
|
||||||
private JLabel actionLabel;
|
private JLabel actionLabel;
|
||||||
private JCheckBox chckbxBlackAI;
|
private JCheckBox chckbxBlackAI;
|
||||||
private JCheckBox chckbxWhiteAI;
|
private JCheckBox chckbxWhiteAI;
|
||||||
|
private JPanelChessBoard chessBoard;
|
||||||
|
private WelcomePanel welcomePanel;
|
||||||
|
private CardLayout cardLayout;
|
||||||
|
private JPanel mainPanel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create the frame.
|
* Create the frame.
|
||||||
|
|
@ -60,7 +64,6 @@ public class MyInterface extends JFrame {
|
||||||
contentPane.add(panelRight, BorderLayout.EAST);
|
contentPane.add(panelRight, BorderLayout.EAST);
|
||||||
panelRight.setLayout(new GridLayout(4,1));
|
panelRight.setLayout(new GridLayout(4,1));
|
||||||
|
|
||||||
|
|
||||||
actionLabel = new JLabel("Waiting For Start");
|
actionLabel = new JLabel("Waiting For Start");
|
||||||
panelTop.add(actionLabel);
|
panelTop.add(actionLabel);
|
||||||
|
|
||||||
|
|
@ -112,7 +115,6 @@ public class MyInterface extends JFrame {
|
||||||
public void actionPerformed(ActionEvent arg0) {
|
public void actionPerformed(ActionEvent arg0) {
|
||||||
clicUndoButton();
|
clicUndoButton();
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
panelTop.add(btnUndo);
|
panelTop.add(btnUndo);
|
||||||
|
|
||||||
|
|
@ -121,7 +123,6 @@ public class MyInterface extends JFrame {
|
||||||
public void actionPerformed(ActionEvent arg0) {
|
public void actionPerformed(ActionEvent arg0) {
|
||||||
clicAIToggle(true);
|
clicAIToggle(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
panelTop.add(chckbxWhiteAI);
|
panelTop.add(chckbxWhiteAI);
|
||||||
|
|
||||||
|
|
@ -130,12 +131,31 @@ public class MyInterface extends JFrame {
|
||||||
public void actionPerformed(ActionEvent arg0) {
|
public void actionPerformed(ActionEvent arg0) {
|
||||||
clicAIToggle(false);
|
clicAIToggle(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
panelTop.add(chckbxBlackAI);
|
panelTop.add(chckbxBlackAI);
|
||||||
|
|
||||||
panelDraw = new JPanelChessBoard(this);
|
// Create card layout for switching panels
|
||||||
contentPane.add(panelDraw, BorderLayout.CENTER);
|
cardLayout = new CardLayout();
|
||||||
|
mainPanel = new JPanel(cardLayout);
|
||||||
|
|
||||||
|
// Create panels
|
||||||
|
welcomePanel = new WelcomePanel(this);
|
||||||
|
chessBoard = new JPanelChessBoard(this);
|
||||||
|
|
||||||
|
// Add panels to card layout
|
||||||
|
mainPanel.add(welcomePanel, "welcome");
|
||||||
|
mainPanel.add(chessBoard, "game");
|
||||||
|
|
||||||
|
// Show welcome screen first
|
||||||
|
cardLayout.show(mainPanel, "welcome");
|
||||||
|
|
||||||
|
// Add main panel to frame
|
||||||
|
contentPane.add(mainPanel, BorderLayout.CENTER);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void showGameBoard() {
|
||||||
|
cardLayout.show(mainPanel, "game");
|
||||||
|
instantiateSimu(); // Initialize the game
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setStepBanner(String s) {
|
public void setStepBanner(String s) {
|
||||||
|
|
@ -147,13 +167,13 @@ public class MyInterface extends JFrame {
|
||||||
}
|
}
|
||||||
|
|
||||||
public JPanelChessBoard getPanelDessin() {
|
public JPanelChessBoard getPanelDessin() {
|
||||||
return panelDraw;
|
return chessBoard;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void instantiateSimu() {
|
public void instantiateSimu() {
|
||||||
if(game == null) {
|
if(game == null) {
|
||||||
game = new Game(this);
|
game = new Game(this);
|
||||||
panelDraw.setGame(game);
|
chessBoard.setGame(game);
|
||||||
game.start();
|
game.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -164,10 +184,11 @@ public class MyInterface extends JFrame {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clickButtonAdder() {
|
public void clickButtonAdder() {
|
||||||
panelDraw.toggleAdderMode();
|
chessBoard.toggleAdderMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clickButtonSelector() {
|
public void clickButtonSelector() {
|
||||||
panelDraw.togglePieceSelector();
|
chessBoard.togglePieceSelector();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void clicUndoButton() {
|
private void clicUndoButton() {
|
||||||
|
|
@ -176,8 +197,8 @@ public class MyInterface extends JFrame {
|
||||||
} else {
|
} else {
|
||||||
game.undoLastMove();
|
game.undoLastMove();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clicAIToggle(boolean isWhite) {
|
public void clicAIToggle(boolean isWhite) {
|
||||||
if(game == null) {
|
if(game == null) {
|
||||||
System.out.println("error : can't activate AI while no game present");
|
System.out.println("error : can't activate AI while no game present");
|
||||||
|
|
@ -210,7 +231,7 @@ public class MyInterface extends JFrame {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
game = loadedSim;
|
game = loadedSim;
|
||||||
panelDraw.setGame(game);
|
chessBoard.setGame(game);
|
||||||
this.repaint();
|
this.repaint();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -256,8 +277,8 @@ public class MyInterface extends JFrame {
|
||||||
|
|
||||||
public void update(int turnCount, boolean turnIsWhite) {
|
public void update(int turnCount, boolean turnIsWhite) {
|
||||||
turnLabel.setText("Turn : "+turnCount+", "+ (turnIsWhite?"White":"Black"));
|
turnLabel.setText("Turn : "+turnCount+", "+ (turnIsWhite?"White":"Black"));
|
||||||
actionLabel.setText(panelDraw.isPieceAdderMode()?"Adding Piece":
|
actionLabel.setText(chessBoard.isPieceAdderMode()?"Adding Piece":
|
||||||
(panelDraw.isPieceSelectorMode()?"Selecting Piece to Add":
|
(chessBoard.isPieceSelectorMode()?"Selecting Piece to Add":
|
||||||
"Playing"));
|
"Playing"));
|
||||||
this.repaint();
|
this.repaint();
|
||||||
}
|
}
|
||||||
|
|
@ -265,5 +286,4 @@ public class MyInterface extends JFrame {
|
||||||
public void eraseLabels() {
|
public void eraseLabels() {
|
||||||
this.setStepBanner("Turn : X");
|
this.setStepBanner("Turn : X");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,46 @@
|
||||||
|
package windowInterface;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import javax.swing.*;
|
||||||
|
|
||||||
|
public class WelcomePanel extends JPanel {
|
||||||
|
private JButton startButton;
|
||||||
|
private MyInterface mainInterface;
|
||||||
|
|
||||||
|
public WelcomePanel(MyInterface mainInterface) {
|
||||||
|
this.mainInterface = mainInterface;
|
||||||
|
setLayout(new BorderLayout());
|
||||||
|
setBackground(new Color(0, 100, 0)); // Dark green background
|
||||||
|
|
||||||
|
// Create title label
|
||||||
|
JLabel titleLabel = new JLabel("Chess Game", SwingConstants.CENTER);
|
||||||
|
titleLabel.setFont(new Font("Serif", Font.BOLD, 48));
|
||||||
|
titleLabel.setForeground(Color.WHITE);
|
||||||
|
titleLabel.setBorder(BorderFactory.createEmptyBorder(50, 0, 30, 0));
|
||||||
|
|
||||||
|
// Create subtitle label
|
||||||
|
JLabel subtitleLabel = new JLabel("Let the game begin!", SwingConstants.CENTER);
|
||||||
|
subtitleLabel.setFont(new Font("Serif", Font.ITALIC, 24));
|
||||||
|
subtitleLabel.setForeground(new Color(234, 235, 200)); // Light green
|
||||||
|
|
||||||
|
// Create start button
|
||||||
|
startButton = new JButton("Start Game");
|
||||||
|
startButton.setFont(new Font("SansSerif", Font.BOLD, 18));
|
||||||
|
startButton.setBackground(new Color(119, 149, 86)); // Dark green
|
||||||
|
startButton.setForeground(Color.WHITE);
|
||||||
|
startButton.setBorder(BorderFactory.createEmptyBorder(10, 30, 10, 30));
|
||||||
|
startButton.addActionListener(e -> mainInterface.showGameBoard());
|
||||||
|
|
||||||
|
// Center panel for button
|
||||||
|
JPanel buttonPanel = new JPanel();
|
||||||
|
buttonPanel.setOpaque(false);
|
||||||
|
buttonPanel.add(startButton);
|
||||||
|
|
||||||
|
// Add components
|
||||||
|
add(titleLabel, BorderLayout.NORTH);
|
||||||
|
add(subtitleLabel, BorderLayout.CENTER);
|
||||||
|
add(buttonPanel, BorderLayout.SOUTH);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue