reorganized code

This commit is contained in:
CT
2026-04-21 22:43:13 -05:00
parent 94e4377364
commit 7f9cdfea63
4 changed files with 26 additions and 15 deletions

View File

@@ -1,15 +1,12 @@
import java.awt.*;
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 {
// pieces stuff
ArrayList<Piece> white;
ArrayList<Piece> black;
Board board;
// game vars
int boardWidth, boardHeight;
@@ -25,15 +22,7 @@ public class Chess extends JPanel implements ActionListener {
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"));
}
board = new Board();
gameTimer = new Timer(200, this);
@@ -54,8 +43,7 @@ public class Chess extends JPanel implements ActionListener {
}
// draw pieces
for (Piece p : white) p.draw(g);
for (Piece p : black) p.draw(g);
board.draw(g);
}
public void paintComponent(Graphics g) {