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
): number {
let buttons = [
chii,
pon,
kan,
ron,
tsumo
[tsumo, 5],
[ron, 4],
[kan, 3],
[pon, 2],
[chii, 1]
]
if (buttons.some(c => c)) {
buttons.unshift(true);
if (buttons.some(c => c[0])) {
buttons.push([true, 0]);
} else {
return -1;
}
let dx = 0;
let size = 0.6;
let xmin = 1025 - buttons.filter(c => c).length * 3 * size;
console.log(x > xmin, "\n");
let xmin = 960 - buttons.filter(c => c[0]).length * 120;
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;
}

View file

@ -97,25 +97,27 @@ export class Game {
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.turn = 0;
this.pick(0);
} else {
this.turn++;
if (this.turn === 3) {
this.turn = 0;
this.pick(0);
} 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 {
this.getSelected(mp);
} else { // nothing unusual
if (this.turn === 0 && this.selectedTile !== undefined) {
this.discard(0, this.selectedTile as NonNullable<number>);
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 {
console.log("Pon !\n");
let t = this.discards[p].pop() as NonNullable<Tile>;
this.lastDiscard = undefined;
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>;
[t, t2, t3].forEach(t => t.setTilt());
this.groups[0].push(new Group([t, t2, t3], p));
this.turn = 0;
this.hasPicked = true;
this.hasPlayed = false;
}
private canDoAChii(): Array<number> {