」 feat(front): added tetris front and some minor fixes

This commit is contained in:
y-syo
2025-10-20 16:18:48 +02:00
parent 8a9224bd88
commit b5a91f0bab
8 changed files with 938 additions and 32 deletions

View File

@ -1,6 +1,7 @@
import Aview from "./Aview.ts";
import { isLogged } from "../main.js";
import { dragElement } from "./drag.js";
import { setOnekoState, setBallPos, setOnekoOffset } from "../oneko.ts"
import { setOnekoState, setBallPos, setOnekoOffset } from "../oneko.ts";
export default class extends Aview {
running: boolean;
@ -538,12 +539,12 @@ export default class extends Aview {
else if (e.code === "Space") {
e.preventDefault();
this.hardDrop();
} else if (e.code === "ShiftLeft") {
} else if (e.key === "Shift" || e.key === "c" || e.key === "C") {
e.preventDefault();
this.hold();
} else if (e.key === "x" || e.key === "X" || e.key === "ArrowUp")
this.rotatePiece("cw");
else if (e.key === "z" || e.key === "Z" || e.code === "ControlLeft")
else if (e.key === "z" || e.key === "Z" || e.key === "Control")
this.rotatePiece("ccw");
});
@ -552,7 +553,7 @@ export default class extends Aview {
});
}
loop(timestamp: number) {
async loop(timestamp: number) {
if (!this.lastDrop) this.lastDrop = timestamp;
if (!this.isPaused)
{
@ -580,6 +581,22 @@ export default class extends Aview {
if (this.isGameOver)
{
if (await isLogged())
{
let uuid = document.cookie.match(new RegExp('(^| )' + "uuid" + '=([^;]+)'))[2];
fetch(`http://localhost:3002/users/${uuid}/matchHistory?game=tetris`, {
method: "POST",
headers: { "Content-Type": "application/json", },
credentials: "include",
body: JSON.stringify({
"game": "tetris",
"opponent": "xd",
"myScore": this.score,
"opponentScore": 0,
"date": Date.now(),
}),
});
}
document.getElementById("game-buttons")?.classList.remove("hidden");
return ;
}