59 lines
1.3 KiB
Java
59 lines
1.3 KiB
Java
import java.awt.*;
|
|
import java.awt.Color;
|
|
import java.awt.event.*;
|
|
import javax.swing.*;
|
|
|
|
public class Chess extends JPanel implements ActionListener {
|
|
|
|
// pieces stuff
|
|
Board board;
|
|
|
|
// game vars
|
|
int boardWidth, boardHeight;
|
|
boolean whiteTurn;
|
|
Timer gameTimer;
|
|
Color creme = new Color(254, 245, 218);
|
|
Color brown = new Color(121, 92, 50);
|
|
|
|
public Chess(int boardWidth, int boardHeight) {
|
|
this.boardWidth = boardWidth;
|
|
this.boardHeight = boardHeight;
|
|
setPreferredSize(new Dimension(this.boardWidth, this.boardHeight));
|
|
setBackground(Color.WHITE);
|
|
setFocusable(true);
|
|
|
|
board = new Board();
|
|
|
|
gameTimer = new Timer(200, this);
|
|
|
|
gameTimer.start();
|
|
repaint();
|
|
}
|
|
|
|
public void gameLoop() {}
|
|
|
|
public void draw(Graphics g) {
|
|
|
|
// draw board
|
|
for (int i = 1; i <= 8; i++) {
|
|
for (int j = 1; j <= 8; j++) {
|
|
g.setColor((i % 2 == 1 && j % 2 == 1) || (i % 2 == 0 && j % 2 == 0) ? creme : brown);
|
|
g.fillRect(i * 40, j * 40, 40, 40);
|
|
}
|
|
}
|
|
|
|
// draw pieces
|
|
board.draw(g);
|
|
}
|
|
|
|
public void paintComponent(Graphics g) {
|
|
super.paintComponent(g);
|
|
draw(g);
|
|
}
|
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
gameLoop();
|
|
repaint();
|
|
}
|
|
}
|