Skip to content

Commit

Permalink
Add letters and x,y on canvas (#85)
Browse files Browse the repository at this point in the history
* Feature/save game (#65)

* feat: add saving game

* refactor

* fix

* fix: some bug

* feat: better ai

* fix: tests en passant

* fix: isValidMove returns true for en passant capture

* fix: isValidMove returns true for en passant capture

* fix: add true

* Create CODE_OF_CONDUCT.md

Signed-off-by: Antoine Greuzard <[email protected]>

* Update issue templates

* refactor ai

* refactor board

* refactor piece

* refactor pieces

* refactor utils

* refactor canvas

* refactor timer

* fix: drag impossible on ai pieces

* fix: remove save game

---------

Signed-off-by: Antoine Greuzard <[email protected]>
Co-authored-by: Antoine GREUZARD <[email protected]>

* fix: remove saveGameToFile

* Update pull_request_template.md

Signed-off-by: Antoine Greuzard <[email protected]>

* fix: remove saveGameToFile

* refactor: add ai folder

* Create dependabot.yml

Signed-off-by: Antoine Greuzard <[email protected]>

* feat: add some jobs

* fix: add token

* fix: rename token to github_token

* feat: add letters and x,y on canvas

* remove dependabot

---------

Signed-off-by: Antoine Greuzard <[email protected]>
Co-authored-by: Antoine GREUZARD <[email protected]>
  • Loading branch information
antoinegreuzard and Antoine GREUZARD authored Nov 1, 2024
1 parent b7a598f commit 73fa670
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
- name: Check bundle size
uses: andresz1/size-limit-action@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
github_token: ${{ secrets.GITHUB_TOKEN }}

deploy:
runs-on: ubuntu-latest
Expand Down
21 changes: 21 additions & 0 deletions src/canvas-renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ export class CanvasRenderer {

// Dessiner les cases de l'échiquier
private drawTiles(): void {
const letters = 'abcdefgh';

for (let y = 0; y < 8; y++) {
for (let x = 0; x < 8; x++) {
const { x: newX, y: newY } = this.getCoordinates(x, y);
Expand All @@ -138,6 +140,25 @@ export class CanvasRenderer {
);
}
}

// Dessiner les indicateurs a-h et 1-8
this.context.font = '16px Arial';
this.context.fillStyle = 'black';
for (let i = 0; i < 8; i++) {
// Afficher les lettres a-h en bas
const letterX =
this.getCoordinates(i, 0).x * this.tileSize + this.tileSize / 2;
const letterY = this.canvas.height - 5;
this.context.textAlign = 'center';
this.context.fillText(letters[i], letterX, letterY);

// Afficher les numéros 1-8 sur le côté
const numberX = 5;
const numberY =
this.getCoordinates(0, i).y * this.tileSize + this.tileSize / 2;
this.context.textBaseline = 'middle';
this.context.fillText(`${8 - i}`, numberX, numberY);
}
}

// Dessiner toutes les pièces sur l'échiquier
Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ export async function initializeGame(playerColor: PieceColor) {
toY: number,
pieceType: PieceType,
) {
const moveText = `${getPieceSymbol(pieceType, currentPlayer)} de (${fromX}, ${fromY}) à (${toX}, ${toY})`;
const letters = 'abcdefgh';
const moveText = `${getPieceSymbol(pieceType, currentPlayer)} de (${letters[fromX]}${8 - fromY}) à (${letters[toX]}${8 - toY})`;
const listItem = document.createElement('li');
listItem.textContent = moveText;

Expand Down

0 comments on commit 73fa670

Please sign in to comment.