Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#76] Added piece icons in logs #97

Merged
merged 4 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions development/src/logic/logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,11 +294,23 @@ function killPieceProcess(
targetPiece: Piece,
targetPosition: Position,
) {
const targetPieceLogo = targetPiece.pieceLogo;
const targetPieceColor = targetPiece.player.color;
const targetPieceName = targetPiece.name;
const draggedPieceLogo = draggedPiece.pieceLogo;
const draggedPieceColor = draggedPiece.player.color;
const draggedPieceName = draggedPiece.name;

if (targetPiece.position.board === OVERWORLD_BOARD_ID) {
targetPiece.position = targetPosition;

Logger.logKill(`A ${targetPiece.player.color} ${targetPiece.name}
was killed by a ${draggedPiece.player.color} ${draggedPiece.name}.`);
Logger.logKill(
`A
${targetPieceLogo} ${targetPieceColor} ${targetPieceName}
was killed by a
${draggedPieceLogo} ${draggedPieceColor} ${draggedPieceName}
.`,
);

if (targetPiece.hasKilled) {
targetPiece.position = {
Expand Down Expand Up @@ -327,9 +339,13 @@ function killPieceProcess(

spawnPieceOnBoard(targetPiece);
} else {
Logger.logKill(`A ${targetPiece.player.color} ${targetPiece.name} was
permanently killed by a ${draggedPiece.player.color}
${draggedPiece.name}.`);
Logger.logKill(
`A
${targetPieceLogo} ${targetPieceColor} ${targetPieceName}
was permanently killed by a
${draggedPieceLogo} ${draggedPieceColor} ${draggedPieceName}
.`,
);

pieces.forEach((piece) => {
const areOnTheSamePosition = comparePositions(
Expand Down Expand Up @@ -401,7 +417,9 @@ function castle(kingPiece: Piece, targetSquare: Square) {

const rookPieceTargetSquare: Square = { position: rookPieceTargetPosition };
move(rookPiece, rookPieceTargetSquare, false);
Logger.logGeneral(`${kingPiece.player.color} castled.`);
Logger.logGeneral(
`${kingPiece.pieceLogo} ${kingPiece.player.color} castled.`,
);
return true;
}

Expand Down
35 changes: 29 additions & 6 deletions development/src/logic/pieces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,21 @@ export class Piece implements PieceType {
name: string;
hasMoved: boolean;
hasKilled: boolean;
pieceLogo: string;
constructor(
position: Position,
player: Player,
resource: string,
name: string,
pieceLogo: string,
) {
this.position = position;
this.player = player;
this.resource = resource;
this.name = name;
this.hasMoved = false;
this.hasKilled = false;
this.pieceLogo = pieceLogo;
}

validateMove(_: Piece | Square | Item): Position {
Expand Down Expand Up @@ -89,7 +92,10 @@ export class Pawn extends Piece {
enPassant: boolean;

constructor(position: Position, player: Player) {
super(position, player, pawnResource, 'Pawn');
const logo = player.color === PlayerColors.WHITE
? '♙'
: '♟';
super(position, player, pawnResource, 'Pawn', logo);
this.enPassant = false;
}

Expand Down Expand Up @@ -158,7 +164,10 @@ export class Pawn extends Piece {

export class Bishop extends Piece {
constructor(position: Position, player: Player) {
super(position, player, bishopResource, 'Bishop');
const logo = player.color === PlayerColors.WHITE
? '♗'
: '♝';
super(position, player, bishopResource, 'Bishop', logo);
}

validateMove(target: Piece | Square) {
Expand Down Expand Up @@ -187,7 +196,10 @@ export class Bishop extends Piece {

export class Knight extends Piece {
constructor(position: Position, player: Player) {
super(position, player, knightResource, 'Knight');
const logo = player.color === PlayerColors.WHITE
? '♘'
: '♞';
super(position, player, knightResource, 'Knight', logo);
}

validateMove(target: Piece | Square) {
Expand All @@ -203,7 +215,10 @@ export class Knight extends Piece {

export class Rook extends Piece {
constructor(position: Position, player: Player) {
super(position, player, rookResource, 'Rook');
const logo = player.color === PlayerColors.WHITE
? '♖'
: '♜';
super(position, player, rookResource, 'Rook', logo);
}

validateMove(target: Piece | Square) {
Expand Down Expand Up @@ -240,7 +255,11 @@ export class Rook extends Piece {

export class Queen extends Piece {
constructor(position: Position, player: Player) {
super(position, player, queenResource, 'Queen');
const logo = player.color === PlayerColors.WHITE
? '♕'
: '♛';

super(position, player, queenResource, 'Queen', logo);
}

validateMove(target: Piece | Square) {
Expand Down Expand Up @@ -284,7 +303,11 @@ export class Queen extends Piece {

export class King extends Piece {
constructor(position: Position, player: Player) {
super(position, player, kingResource, 'King');
const logo = player.color === PlayerColors.WHITE
? '♔'
: '♚';

super(position, player, kingResource, 'King', logo);
}

validateMove(target: Piece | Square) {
Expand Down
12 changes: 10 additions & 2 deletions development/src/ui/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,16 @@ export class Logger {
const toNotation = this.convertPositionToNotation(
targetSquare.position.coordinates,
);
this.log(`${draggedPiece.player.color} ${draggedPiece.name}
moved from ${fromNotation} to ${toNotation}.`, LogColor.movement);

const pieceLogo = `${draggedPiece.pieceLogo}`;
const pieceColor = `${draggedPiece.player.color}`;
const pieceName = `${draggedPiece.name}`;

this.log(`
${pieceLogo} ${pieceColor} ${pieceName}
moved from ${fromNotation} to ${toNotation}.`,
LogColor.movement,
);
}

private static convertPositionToNotation(position: [number, number]) {
Expand Down
Loading