reorganized code
This commit is contained in:
BIN
Board.class
Normal file
BIN
Board.class
Normal file
Binary file not shown.
23
Board.java
Normal file
23
Board.java
Normal file
@@ -0,0 +1,23 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class Board {
|
||||
Piece[][] board;
|
||||
|
||||
public Board() {
|
||||
board = new Piece[8][8];
|
||||
for (int i = 0; i <= 7; i++) {
|
||||
board[i][2] = new Pawn(i + 1, 2, "Black");
|
||||
}
|
||||
for (int i = 0; i <= 7; i++) {
|
||||
board[i][7] = new Pawn(i + 1, 7, "Black");
|
||||
}
|
||||
}
|
||||
|
||||
public void draw(Graphics g) {
|
||||
for (Piece[] row : board) {
|
||||
for (Piece p : row) {
|
||||
if (p != null) p.draw(g);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
Chess.class
BIN
Chess.class
Binary file not shown.
18
Chess.java
18
Chess.java
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user