can now do pon

This commit is contained in:
Didictateur 2025-03-23 21:12:33 +01:00
parent e74eaf0f80
commit 1d48067458
3 changed files with 40 additions and 25 deletions

File diff suppressed because one or more lines are too long

View file

@ -14,21 +14,31 @@ export function clickAction(
tsumo: boolean tsumo: boolean
): number { ): number {
let buttons = [ let buttons = [
chii, [tsumo, 5],
pon, [ron, 4],
kan, [kan, 3],
ron, [pon, 2],
tsumo [chii, 1]
] ]
if (buttons.some(c => c)) { if (buttons.some(c => c[0])) {
buttons.unshift(true); buttons.push([true, 0]);
} else { } else {
return -1; return -1;
} }
let dx = 0; let dx = 0;
let size = 0.6; let size = 0.6;
let xmin = 1025 - buttons.filter(c => c).length * 3 * size; let xmin = 960 - buttons.filter(c => c[0]).length * 120;
console.log(x > xmin, "\n"); let inside = 492 < y && y < 544;
let q = Math.floor((x - xmin) / 120);
let r = (x - xmin) - 120 * q;
if (
q >= 0 &&
q < buttons.filter(c => c[0]).length &&
r > 10
) {
return buttons.filter(c => c[0])[q][1] as number;
}
console.log(q, r, "\n");
return -1; return -1;
} }

View file

@ -97,25 +97,27 @@ export class Game {
false, false,
false false
); );
if (action === -1 && this.canCall) {
if (this.turn === 3) { if (this.canCall && action !== -1) { // can call
if (action === 0) { // pass
this.canCall = false; this.canCall = false;
this.turn = 0; if (this.turn === 3) {
this.pick(0); this.turn = 0;
} else { this.pick(0);
this.turn++; } else {
this.turn++;
}
this.hasPicked = false;
this.hasPlayed = false;
} else if (action == 2) { // pon
this.pon(this.turn);
} }
this.hasPicked = false;
this.hasPlayed = false; } else { // nothing unusual
} else {
this.getSelected(mp);
if (this.turn === 0 && this.selectedTile !== undefined) { if (this.turn === 0 && this.selectedTile !== undefined) {
this.discard(0, this.selectedTile as NonNullable<number>); this.discard(0, this.selectedTile as NonNullable<number>);
this.turn++; this.turn++;
} }
if (this.canDoAPon()) {
this.pon(this.turn > 0 ? this.turn-1 : 3);
}
} }
} }
@ -199,13 +201,16 @@ export class Game {
} }
private pon(p: number): void { private pon(p: number): void {
console.log("Pon !\n");
let t = this.discards[p].pop() as NonNullable<Tile>; let t = this.discards[p].pop() as NonNullable<Tile>;
this.lastDiscard = undefined; this.lastDiscard = undefined;
let t2 = this.hands[0].find(t.getFamily(), t.getValue()) as NonNullable<Tile>; let t2 = this.hands[0].find(t.getFamily(), t.getValue()) as NonNullable<Tile>;
let t3 = this.hands[0].find(t.getFamily(), t.getValue()) as NonNullable<Tile>; let t3 = this.hands[0].find(t.getFamily(), t.getValue()) as NonNullable<Tile>;
[t, t2, t3].forEach(t => t.setTilt()); [t, t2, t3].forEach(t => t.setTilt());
this.groups[0].push(new Group([t, t2, t3], p)); this.groups[0].push(new Group([t, t2, t3], p));
this.turn = 0;
this.hasPicked = true;
this.hasPlayed = false;
} }
private canDoAChii(): Array<number> { private canDoAChii(): Array<number> {