Color green + Welcome interface
This commit is contained in:
parent
2ba7cccbf4
commit
9fd3642203
|
|
@ -117,9 +117,6 @@ public class Board {
|
|||
}
|
||||
return pieces;
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public boolean isSelected(int x, int y) {
|
||||
|
|
@ -127,13 +124,6 @@ public class Board {
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public void userTouch(int x, int y) {
|
||||
if (x < 0 || x >= width || y < 0 || y >= height) return;
|
||||
|
||||
|
|
@ -171,7 +161,7 @@ public class Board {
|
|||
board[selectedX][selectedY] = null;
|
||||
selectedPiece.setX(x);
|
||||
selectedPiece.setY(y);
|
||||
selectedPiece.setMoved(true); // ✅ Marque la pièce comme ayant bougé
|
||||
selectedPiece.setMoved(true);
|
||||
|
||||
|
||||
// Déplacement de la tour si roque
|
||||
|
|
|
|||
|
|
@ -77,10 +77,12 @@ public class JPanelChessBoard extends JPanel {
|
|||
myGame = simu;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
this.setBackground(Color.black);
|
||||
this.setBackground(new Color(0, 100, 0)); // Dark green background
|
||||
|
||||
if(pieceSelectorMode) {
|
||||
g.drawImage(
|
||||
spriteSheet,
|
||||
|
|
@ -92,23 +94,34 @@ public class JPanelChessBoard extends JPanel {
|
|||
);
|
||||
return;
|
||||
}
|
||||
|
||||
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 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++) {
|
||||
boolean isSelect = myGame.isSelected(x,y);
|
||||
boolean isHighlight = myGame.isHighlighted(x,y);
|
||||
|
||||
// Set square color
|
||||
if(isSelect) {
|
||||
g.setColor(Color.blue);
|
||||
g.setColor(selectBlue);
|
||||
}
|
||||
if(isHighlight) {
|
||||
g.setColor(Color.yellow);
|
||||
else if(isHighlight) {
|
||||
g.setColor(highlightYellow);
|
||||
}
|
||||
if((x+y)%2==1 || isSelect || isHighlight) {
|
||||
else {
|
||||
g.setColor((x + y) % 2 == 0 ? lightGreen : darkGreen);
|
||||
}
|
||||
|
||||
g.fillRect(
|
||||
Math.round(x*cellWidth),
|
||||
Math.round(y*cellHeight),
|
||||
|
|
@ -116,15 +129,11 @@ public class JPanelChessBoard extends JPanel {
|
|||
Math.round(cellHeight)
|
||||
);
|
||||
}
|
||||
if(isHighlight || isSelect) {
|
||||
g.setColor(Color.white);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
g.setColor(Color.gray);
|
||||
for(int x=0; x<myGame.getWidth();x++) {
|
||||
// Draw grid lines (optional)
|
||||
g.setColor(new Color(0, 80, 0)); // Darker green for grid lines
|
||||
for(int x=0; x<myGame.getWidth(); x++) {
|
||||
int graphX = Math.round(x*cellWidth);
|
||||
g.drawLine(graphX, 0, graphX, this.getHeight());
|
||||
}
|
||||
|
|
@ -133,8 +142,9 @@ public class JPanelChessBoard extends JPanel {
|
|||
g.drawLine(0, graphY, this.getWidth(), graphY);
|
||||
}
|
||||
|
||||
// Draw pieces
|
||||
for (Piece piece : myGame.getPieces()) {
|
||||
drawPiece(g,piece);
|
||||
drawPiece(g, piece);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package windowInterface;
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.CardLayout;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.GridLayout;
|
||||
|
||||
|
|
@ -37,11 +38,14 @@ public class MyInterface extends JFrame {
|
|||
private JLabel turnLabel;
|
||||
private JLabel borderLabel;
|
||||
private JLabel speedLabel;
|
||||
private JPanelChessBoard panelDraw;
|
||||
private Game game;
|
||||
private JLabel actionLabel;
|
||||
private JCheckBox chckbxBlackAI;
|
||||
private JCheckBox chckbxWhiteAI;
|
||||
private JPanelChessBoard chessBoard;
|
||||
private WelcomePanel welcomePanel;
|
||||
private CardLayout cardLayout;
|
||||
private JPanel mainPanel;
|
||||
|
||||
/**
|
||||
* Create the frame.
|
||||
|
|
@ -60,7 +64,6 @@ public class MyInterface extends JFrame {
|
|||
contentPane.add(panelRight, BorderLayout.EAST);
|
||||
panelRight.setLayout(new GridLayout(4,1));
|
||||
|
||||
|
||||
actionLabel = new JLabel("Waiting For Start");
|
||||
panelTop.add(actionLabel);
|
||||
|
||||
|
|
@ -112,7 +115,6 @@ public class MyInterface extends JFrame {
|
|||
public void actionPerformed(ActionEvent arg0) {
|
||||
clicUndoButton();
|
||||
}
|
||||
|
||||
});
|
||||
panelTop.add(btnUndo);
|
||||
|
||||
|
|
@ -121,7 +123,6 @@ public class MyInterface extends JFrame {
|
|||
public void actionPerformed(ActionEvent arg0) {
|
||||
clicAIToggle(true);
|
||||
}
|
||||
|
||||
});
|
||||
panelTop.add(chckbxWhiteAI);
|
||||
|
||||
|
|
@ -130,12 +131,31 @@ public class MyInterface extends JFrame {
|
|||
public void actionPerformed(ActionEvent arg0) {
|
||||
clicAIToggle(false);
|
||||
}
|
||||
|
||||
});
|
||||
panelTop.add(chckbxBlackAI);
|
||||
|
||||
panelDraw = new JPanelChessBoard(this);
|
||||
contentPane.add(panelDraw, BorderLayout.CENTER);
|
||||
// Create card layout for switching panels
|
||||
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) {
|
||||
|
|
@ -147,13 +167,13 @@ public class MyInterface extends JFrame {
|
|||
}
|
||||
|
||||
public JPanelChessBoard getPanelDessin() {
|
||||
return panelDraw;
|
||||
return chessBoard;
|
||||
}
|
||||
|
||||
public void instantiateSimu() {
|
||||
if(game==null) {
|
||||
if(game == null) {
|
||||
game = new Game(this);
|
||||
panelDraw.setGame(game);
|
||||
chessBoard.setGame(game);
|
||||
game.start();
|
||||
}
|
||||
}
|
||||
|
|
@ -164,10 +184,11 @@ public class MyInterface extends JFrame {
|
|||
}
|
||||
|
||||
public void clickButtonAdder() {
|
||||
panelDraw.toggleAdderMode();
|
||||
chessBoard.toggleAdderMode();
|
||||
}
|
||||
|
||||
public void clickButtonSelector() {
|
||||
panelDraw.togglePieceSelector();
|
||||
chessBoard.togglePieceSelector();
|
||||
}
|
||||
|
||||
private void clicUndoButton() {
|
||||
|
|
@ -176,8 +197,8 @@ public class MyInterface extends JFrame {
|
|||
} else {
|
||||
game.undoLastMove();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void clicAIToggle(boolean isWhite) {
|
||||
if(game == null) {
|
||||
System.out.println("error : can't activate AI while no game present");
|
||||
|
|
@ -210,7 +231,7 @@ public class MyInterface extends JFrame {
|
|||
e.printStackTrace();
|
||||
}
|
||||
game = loadedSim;
|
||||
panelDraw.setGame(game);
|
||||
chessBoard.setGame(game);
|
||||
this.repaint();
|
||||
}
|
||||
}
|
||||
|
|
@ -256,8 +277,8 @@ public class MyInterface extends JFrame {
|
|||
|
||||
public void update(int turnCount, boolean turnIsWhite) {
|
||||
turnLabel.setText("Turn : "+turnCount+", "+ (turnIsWhite?"White":"Black"));
|
||||
actionLabel.setText(panelDraw.isPieceAdderMode()?"Adding Piece":
|
||||
(panelDraw.isPieceSelectorMode()?"Selecting Piece to Add":
|
||||
actionLabel.setText(chessBoard.isPieceAdderMode()?"Adding Piece":
|
||||
(chessBoard.isPieceSelectorMode()?"Selecting Piece to Add":
|
||||
"Playing"));
|
||||
this.repaint();
|
||||
}
|
||||
|
|
@ -265,5 +286,4 @@ public class MyInterface extends JFrame {
|
|||
public void eraseLabels() {
|
||||
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