Skip to content

Commit

Permalink
Fixed some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
MitchellGray100 committed Sep 12, 2021
1 parent 58cd33b commit c4a4181
Show file tree
Hide file tree
Showing 13 changed files with 19 additions and 15 deletions.
Binary file modified bin/Black Pawn.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified bin/White pawn.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified bin/application/Main$HorizontalBorderTile.class
Binary file not shown.
Binary file modified bin/application/Main$LeftTextTile.class
Binary file not shown.
Binary file modified bin/application/Main$Piece.class
Binary file not shown.
Binary file modified bin/application/Main$ScoreTile.class
Binary file not shown.
Binary file modified bin/application/Main$Tile.class
Binary file not shown.
Binary file modified bin/application/Main$TopTextTile.class
Binary file not shown.
Binary file modified bin/application/Main$VerticalBorderTile.class
Binary file not shown.
Binary file modified bin/application/Main.class
Binary file not shown.
Binary file modified bin/controller/ControllerImpl.class
Binary file not shown.
26 changes: 15 additions & 11 deletions src/application/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class Main extends Application {
private int lastMovementY = -1;
private int movedPieceX = -1;
private int movedPieceY = -1;
private Image image = null;

private Parent createContent() {
GridPane grid = new GridPane();
Expand Down Expand Up @@ -225,8 +226,7 @@ public TopTextTile(String textInput) {

private class Piece extends StackPane {
// private Text text = new Text();
private Image image = null;
private ImageView imageView = new ImageView(image);
private ImageView imageView = null;
private LocationImpl location;
private Color color;
private Circle indicator = new Circle(70, 70, 32, null);
Expand Down Expand Up @@ -267,7 +267,14 @@ public Piece(Color color, LocationImpl location) {
if (game.getTurns() % 2 != 0) {
if (event.getButton() == MouseButton.PRIMARY) {

if (!clicked && game.squareInfo(location.getXAxis(), location.getYAxis()) != null
if (game.isCheckmate(piecesPackage.Piece.Color.BLACK)) {
System.out.println("White Won The Game!");
} else if (game.isCheckmate(piecesPackage.Piece.Color.WHITE)) {
System.out.println("Black Won The Game!");
} else if (game.isStalemate(piecesPackage.Piece.Color.BLACK)
|| game.isStalemate(piecesPackage.Piece.Color.WHITE)) {
System.out.println("STALEMATE. Tie Game");
} else if (!clicked && game.squareInfo(location.getXAxis(), location.getYAxis()) != null
&& game.squareInfo(location.getXAxis(), location.getYAxis())
.getColor() != piecesPackage.Piece.Color.WHITE) {
displayValidMoves(location);
Expand All @@ -287,10 +294,12 @@ public Piece(Color color, LocationImpl location) {
// pieceBoard[movingPieceX][movingPieceY] = new Piece(
// pieceBoard[movingPieceX][movingPieceY].color,
// new LocationImpl(movingPieceX, movingPieceY));

updateScores();
drawBoardPieces();
removeValidMoves();
removeLastPieceColor();

movedPieceX = location.getXAxis();
movedPieceY = location.getYAxis();
lastMovementX = movingPieceX;
Expand All @@ -313,14 +322,16 @@ public Piece(Color color, LocationImpl location) {
movingPieceY = -1;
}
} else {
LocationImpl[] returner = game.aiMoveReturn(piecesPackage.Piece.Color.WHITE);

removeLastPieceColor();
LocationImpl[] returner = game.aiMoveReturn(piecesPackage.Piece.Color.WHITE);
movedPieceX = returner[0].getXAxis();
movedPieceY = returner[0].getYAxis();
lastMovementX = returner[1].getXAxis();
lastMovementY = returner[1].getYAxis();
lastPieceColor();
game.aiMove(piecesPackage.Piece.Color.WHITE);

updateScores();
drawBoardPieces();
game.incrementTurns();
Expand All @@ -331,12 +342,6 @@ public Piece(Color color, LocationImpl location) {
}

public void drawBoardPieces() {
FileInputStream pawnImage = null;
try {
pawnImage = new FileInputStream("src/White Pawn.png");
} catch (FileNotFoundException e) {
e.printStackTrace();
}
for (int r = 0; r < 8; r++) {
for (int c = 0; c < 8; c++) {
try {
Expand Down Expand Up @@ -496,7 +501,6 @@ public void start(Stage primaryStage) throws Exception {

primaryStage.show();
primaryStage.setScene(new Scene(createContent()));

}

public static void main(String[] args) {
Expand Down
8 changes: 4 additions & 4 deletions src/controller/ControllerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,11 @@ public boolean isCheckmate(Piece.Color color) {
int x;
int y;
if (color == piecesPackage.Piece.Color.WHITE) {
x = board.piecesGetter(4).getLocation().getXAxis();
y = board.piecesGetter(4).getLocation().getYAxis();
x = board.piecesGetter(3).getLocation().getXAxis();
y = board.piecesGetter(3).getLocation().getYAxis();
} else {
x = board.piecesGetter(24).getLocation().getXAxis();
y = board.piecesGetter(24).getLocation().getYAxis();
x = board.piecesGetter(19).getLocation().getXAxis();
y = board.piecesGetter(19).getLocation().getYAxis();
}
return board.isCheckmate(x, y);
}
Expand Down

0 comments on commit c4a4181

Please sign in to comment.