AAAAAAAAAAAAAAAAAAAAAAAAA.
This commit is contained in:
@@ -1,8 +1,36 @@
|
|||||||
package chess;
|
package chess;
|
||||||
|
import java.awt.Color;
|
||||||
import java.util.Map;
|
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 {
|
class Board {
|
||||||
Map<Coord, Piece> 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.
|
// Measured from top left.
|
||||||
|
|||||||
@@ -5,8 +5,29 @@ import javalib.impworld.*;
|
|||||||
class Game extends World {
|
class Game extends World {
|
||||||
Actor white;
|
Actor white;
|
||||||
Actor black;
|
Actor black;
|
||||||
|
Board board;
|
||||||
|
WorldScene scene;
|
||||||
|
|
||||||
public WorldScene makeScene() { return new WorldScene(0, 0); }
|
Game(Actor white, Actor black, Board board) {
|
||||||
|
this.white = white;
|
||||||
void run() { this.bigBang(0, 0, 0.01); }
|
this.black = black;
|
||||||
|
this.board = board;
|
||||||
|
}
|
||||||
|
|
||||||
|
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(); }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package chess;
|
package chess;
|
||||||
|
|
||||||
|
import javalib.worldimages.*;
|
||||||
|
|
||||||
// The piece types.
|
// The piece types.
|
||||||
enum PieceType { PAWN, ROOK, KNIGHT, BISHOP, POPE, QUEEN, KING }
|
enum PieceType { PAWN, ROOK, KNIGHT, BISHOP, POPE, QUEEN, KING }
|
||||||
|
|
||||||
@@ -8,8 +10,14 @@ abstract class Piece {
|
|||||||
PieceType type;
|
PieceType type;
|
||||||
|
|
||||||
Piece(PieceType type) { this.type = type; }
|
Piece(PieceType type) { this.type = type; }
|
||||||
|
WorldImage draw() { return new EmptyImage(); };
|
||||||
}
|
}
|
||||||
|
|
||||||
class Pawn extends Piece {
|
class Pawn extends Piece {
|
||||||
Pawn() { super(PieceType.PAWN); }
|
Pawn() { super(PieceType.PAWN); }
|
||||||
|
WorldImage draw() {
|
||||||
|
return new FromFileImage(
|
||||||
|
"/home/jacob/Projects/CS3/chess/imgs/whitePawn.png"
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,9 @@ class Util {
|
|||||||
// Width of a chessboard.
|
// Width of a chessboard.
|
||||||
static int boardW = 8;
|
static int boardW = 8;
|
||||||
|
|
||||||
|
// Scale of the drawn chessboard.
|
||||||
|
static int scale = 64;
|
||||||
|
|
||||||
// The color a piece can be.
|
// The color a piece can be.
|
||||||
enum Col { WHITE, BLACK }
|
enum Col { WHITE, BLACK }
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user