draw hands

This commit is contained in:
Didictateur 2026-02-28 23:08:13 +01:00
parent 4f1d603d2e
commit b131301495
2 changed files with 75 additions and 1 deletions

View file

@ -0,0 +1,62 @@
// import "./tile.js";
class Hand {
constructor(option = {}) {
this.tiles = option.tiles || [];
this.draw = null;
this.sort();
}
sort() {
this.tiles.sort((a, b) => {
if (a.lessThan(b)) return -1;
if (b.lessThan(a)) return 1;
return 0;
});
}
flatten() {
if (this.draw) {
this.tiles.push(this.draw);
this.draw = null;
}
}
}
class Wall {
constructor() {
this.tiles = Tile.generateAll();
for (let i = this.tiles.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[this.tiles[i], this.tiles[j]] = [this.tiles[j], this.tiles[i]];
}
}
draw() {
return this.tiles.pop();
}
drawHand() {
let tiles = [];
for (let i = 0; i < 13; i++) {
tiles.push(this.draw());
}
return new Hand({ tiles });
}
}
class Discard {
constructor() {
this.tiles = [];
this.hiddenTiles = []; // for stollen tiles
}
}
class Game {
constructor() {
this.wall = new Wall();
this.hands = Array.from({ length: 4 }, () => this.wall.drawHand());
this.discards = Array.from({ length: 4 }, () => new Discard());
this.turn = 0;
}
}

View file

@ -163,8 +163,20 @@
? '<img class="explaining" src="/img/tilineau/explaining.png" alt="Tilineau">'
: '<img src="/img/tilineau/idle.png" alt="Tilineau">';
});
});
// Créer une nouvelle partie et afficher les mains
const game = new Game();
console.log(game)
for (let i = 0; i < 4; i++) {
const handDiv = document.getElementById(`hand-${i}`);
handDiv.innerHTML = '';
for (const tile of game.hands[i].tiles) {
const tileDiv = document.createElement('div');
tileDiv.innerHTML = tile.getSVG();
handDiv.appendChild(tileDiv);
}
}
});
</script>
</body>
</html>