Removed color from Piece constructor

This commit is contained in:
Filip Znachor 2023-04-18 11:32:17 +02:00
parent b5f20725c1
commit 920c4e76e4
9 changed files with 28 additions and 32 deletions

View file

@ -46,14 +46,13 @@ public abstract class AbstractPiece implements IPiece {
* @param player player
* @param x piece's X location
* @param y piece's Y location
* @param color piece's color
*/
public AbstractPiece(Player player, int x, int y, PieceColor color) {
public AbstractPiece(Player player, int x, int y) {
this.x = x;
this.y = y;
this.player = player;
this.chessboard = player.getChessboard();
this.color = color;
this.color = player.getColor();
chessboard.addPiece(this, x, y);
}

View file

@ -14,10 +14,9 @@ public class Bishop extends AbstractPiece {
* @param player player
* @param x piece's X location
* @param y piece's Y location
* @param color piece's color
*/
public Bishop(Player player, int x, int y, PieceColor color) {
super(player, x, y, color);
public Bishop(Player player, int x, int y) {
super(player, x, y);
}
/**

View file

@ -1,5 +1,4 @@
import java.awt.*;
import java.util.List;
/**
* Piece's interface

View file

@ -15,10 +15,9 @@ public class King extends AbstractPiece {
* @param player player
* @param x piece's X location
* @param y piece's Y location
* @param color piece's color
*/
public King(Player player, int x, int y, PieceColor color) {
super(player, x, y, color);
public King(Player player, int x, int y) {
super(player, x, y);
}
/**

View file

@ -10,10 +10,9 @@ public class Knight extends AbstractPiece {
* @param player player
* @param x piece's X location
* @param y piece's Y location
* @param color piece's color
*/
public Knight(Player player, int x, int y, PieceColor color) {
super(player, x, y, color);
public Knight(Player player, int x, int y) {
super(player, x, y);
}
/**

View file

@ -10,10 +10,9 @@ public class Pawn extends AbstractPiece {
* @param player player
* @param x piece's X location
* @param y piece's Y location
* @param color piece's color
*/
public Pawn(Player player, int x, int y, PieceColor color) {
super(player, x, y, color);
public Pawn(Player player, int x, int y) {
super(player, x, y);
}
/**
@ -43,7 +42,7 @@ public class Pawn extends AbstractPiece {
public boolean move(PiecePosition pos) {
boolean result = super.move(pos);
int changeY = color == PieceColor.WHITE ? 0 : chessboard.SQUARE_COUNT-1;
if(y == changeY) new Queen(player, x, y, color);
if(y == changeY) new Queen(player, x, y);
return result;
}
}

View file

@ -29,16 +29,16 @@ public class Player {
public void createPieces() {
int first = startPosition == StartPosition.BOTTOM ? 7 : 0;
int second = startPosition == StartPosition.BOTTOM ? 6 : 1;
leftRook = new Rook(this, 0, first, color);
new Knight(this, 1, first, color);
rightRook = new Rook(this, 7, first, color);
new Knight(this, 6, first, color);
new Queen(this, 3, first, color);
new Bishop(this, 5, first, color);
new Bishop(this, 2, first, color);
king = new King(this, 4, first, color);
leftRook = new Rook(this, 0, first);
new Knight(this, 1, first);
rightRook = new Rook(this, 7, first);
new Knight(this, 6, first);
new Queen(this, 3, first);
new Bishop(this, 5, first);
new Bishop(this, 2, first);
king = new King(this, 4, first);
for (int j = 0; j < 8; j++) {
new Pawn(this, j, second, color);
new Pawn(this, j, second);
}
}
@ -46,6 +46,10 @@ public class Player {
return chessboard;
}
public PieceColor getColor() {
return color;
}
public StartPosition getStartPosition() {
return startPosition;
}

View file

@ -13,10 +13,9 @@ public class Queen extends AbstractPiece {
* @param player player
* @param x piece's X location
* @param y piece's Y location
* @param color piece's color
*/
public Queen(Player player, int x, int y, PieceColor color) {
super(player, x, y, color);
public Queen(Player player, int x, int y) {
super(player, x, y);
}
/**

View file

@ -10,10 +10,9 @@ public class Rook extends AbstractPiece {
* @param player player
* @param x piece's X location
* @param y piece's Y location
* @param color piece's color
*/
public Rook(Player player, int x, int y, PieceColor color) {
super(player, x, y, color);
public Rook(Player player, int x, int y) {
super(player, x, y);
}
/**