AAAAAAAAAAAAAAAAAAAAAAAAA.

This commit is contained in:
Jacob Signorovitch
2025-04-28 09:10:13 -04:00
parent 9bdbffdf62
commit e6e85dd60f
4 changed files with 62 additions and 2 deletions

View File

@@ -1,8 +1,36 @@
package chess;
import java.awt.Color;
import java.util.Map;
import javalib.impworld.WorldScene;
import javalib.worldimages.EmptyImage;
import javalib.worldimages.OutlineMode;
import javalib.worldimages.OverlayImage;
import javalib.worldimages.RectangleImage;
class Board {
Map<Coord, Piece> board;
WorldScene draw() {
WorldScene scene =
new WorldScene(Util.boardW * Util.scale, Util.boardW * Util.scale);
for (int i = 0; i < Util.boardW; i++)
for (int j = 0; j < Util.boardW; j++) {
Piece piece = this.board.get(new Coord(i, j));
scene.placeImageXY(
new OverlayImage(
(piece == null) ? new EmptyImage() : piece.draw(),
new RectangleImage(
Util.scale, Util.scale, OutlineMode.SOLID,
(i + j) % 2 == 0 ? Color.BLACK : Color.WHITE
)
),
i * Util.scale + Util.scale / 2,
j * Util.scale + Util.scale / 2
);
}
return scene;
}
}
// Measured from top left.

View File

@@ -5,8 +5,29 @@ import javalib.impworld.*;
class Game extends World {
Actor white;
Actor black;
Board board;
WorldScene scene;
public WorldScene makeScene() { return new WorldScene(0, 0); }
Game(Actor white, Actor black, Board board) {
this.white = white;
this.black = black;
this.board = board;
}
void run() { this.bigBang(0, 0, 0.01); }
Game() {
this(
new Player(Util.Col.WHITE), new Player(Util.Col.BLACK), new Board()
);
}
public WorldScene makeScene() {
this.scene = this.getEmptyScene();
this.draw();
return this.scene;
}
void run() {
this.bigBang(Util.boardW * Util.scale, Util.boardW * Util.scale, 0.01);
}
void draw() { this.scene = this.board.draw(); }
}

View File

@@ -1,5 +1,7 @@
package chess;
import javalib.worldimages.*;
// The piece types.
enum PieceType { PAWN, ROOK, KNIGHT, BISHOP, POPE, QUEEN, KING }
@@ -8,8 +10,14 @@ abstract class Piece {
PieceType type;
Piece(PieceType type) { this.type = type; }
WorldImage draw() { return new EmptyImage(); };
}
class Pawn extends Piece {
Pawn() { super(PieceType.PAWN); }
WorldImage draw() {
return new FromFileImage(
"/home/jacob/Projects/CS3/chess/imgs/whitePawn.png"
);
}
}

View File

@@ -5,6 +5,9 @@ class Util {
// Width of a chessboard.
static int boardW = 8;
// Scale of the drawn chessboard.
static int scale = 64;
// The color a piece can be.
enum Col { WHITE, BLACK }
}