formatting and compiling

This commit is contained in:
Cool Guy
2026-04-21 16:20:03 +00:00
parent 76c4dea36a
commit 94e4377364
7 changed files with 103 additions and 106 deletions

View File

@@ -1,73 +1,70 @@
import java.util.ArrayList;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.border.*;
import java.awt.Color;
import java.awt.event.*;
import java.util.ArrayList;
import javax.swing.*;
import javax.swing.border.*;
public class Chess extends JPanel implements ActionListener {
public class Chess extends JPanel implements ActionListener{
//pieces stuff
ArrayList<Piece> white;
ArrayList<Piece> black;
//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);
white = new ArrayList<>();
black = new ArrayList<>();
for (int i =0 ; i <= 7; i++){
white.add(new Pawn(i+1,2,"White"));
}
for (int i =0 ; i <= 7; i++){
black.add(new Pawn(i+1,7,"Black"));
}
gameTimer = new Timer(200,this);
gameTimer.start();
repaint();
// pieces stuff
ArrayList<Piece> white;
ArrayList<Piece> black;
// 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);
white = new ArrayList<>();
black = new ArrayList<>();
for (int i = 0; i <= 7; i++) {
white.add(new Pawn(i + 1, 2, "White"));
}
public void gameLoop(){
for (int i = 0; i <= 7; i++) {
black.add(new Pawn(i + 1, 7, "Black"));
}
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
for (Piece p : white) p.draw(g);
for (Piece p : black) p.draw(g);
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);
}
}
public void paintComponent(Graphics g){
super.paintComponent(g);
draw(g);
}
public void actionPerformed(ActionEvent e){
gameLoop();
repaint();
}
}
// draw pieces
for (Piece p : white) p.draw(g);
for (Piece p : black) p.draw(g);
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
draw(g);
}
public void actionPerformed(ActionEvent e) {
gameLoop();
repaint();
}
}