(tic-tac-toe): Erratum, it's the join/leave queue button

This commit is contained in:
apetitco 2026-01-07 22:40:48 +01:00 committed by Maix0
parent ca9b2a7320
commit 92eb73c508
5 changed files with 17 additions and 16 deletions

View file

@ -28,8 +28,8 @@ export interface ClientToServer {
gameMove: (up: GameMove) => void;
keepalive: () => void;
connectedToGame: (gameId: string) => void;
// TODO
requestNewGame: () => void;
// TODO:
joinQueueButton: () => void;
};
export interface ServerToClient {

View file

@ -1,6 +1,6 @@
<div class="displaybox">
<div id="mainbox" class="mainboxDisplay">
<button id="NewGameBtn" class="btn-style absolute top-4 right-6">New Game</button>
<button id="JoinQueueBtn" class="btn-style absolute top-4 right-6">New Game</button>
<h1 class="text-3xl font-bold text-gray-800">
Tic-tac-toe Box<span id="t-username"></span>
</h1><br>

View file

@ -45,20 +45,20 @@ async function handleTTT(): Promise<RouteHandlerReturn> {
if (user === null)
return;
const newGameBtn = document.querySelector<HTMLButtonElement>("#NewGameBtn");
const joinQueueBtn = document.querySelector<HTMLButtonElement>("#JoinQueueBtn");
if (!newGameBtn) {
if (!joinQueueBtn) {
return showError('fatal error');
}
// TODO
// TODO: Join queue button
// When clicking on this button, two scenarios:
// not in a game -> Join queue
// In a game -> user clicking on the button loses the game and joins the queue, board is cleaned
// Should I differentiate the scenarios here or inside the requestNewGame function ?
newGameBtn.addEventListener("click", () => {
console.log('===== NEW GAME REQUESTED =====');
socket.emit("requestNewGame");
joinQueueBtn.addEventListener("click", () => {
console.log('===== JOIN QUEUE BUTTON PRESSED =====');
socket.emit("joinQueueButton");
});
let curGame: CurrentGameInfo | null = null;

View file

@ -28,7 +28,8 @@ export interface ClientToServer {
gameMove: (up: GameMove) => void;
keepalive: () => void;
connectedToGame: (gameId: string) => void;
requestNewGame: () => void;
// TODO:
joinQueueButton: () => void;
};
export interface ServerToClient {

View file

@ -48,8 +48,8 @@ export class StateI {
socket.on('enqueue', () => this.enqueueUser(socket));
socket.on('dequeue', () => this.dequeueUser(socket));
socket.on('debugInfo', () => this.debugSocket(socket));
// TODO
socket.on('requestNewGame', () => this.requestNewGame(socket));
// TODO:
socket.on('joinQueueButton', () => this.joinQueueButton(socket));
socket.on('gameMove', (e) => this.gameMove(socket, e));
socket.on('keepalive', () => this.keepAlive(socket));
@ -205,11 +205,11 @@ export class StateI {
game?.makeMove(socket.authUser.id, update.index);
}
// TODO
private requestNewGame(socket: SSocket) {
// TODO:
private joinQueueButton(socket: SSocket) {
void socket;
// TODO
this.fastify.log.info('===== NEW GAME REQUESTED =====');
// TODO:
this.fastify.log.info('===== JOIN QUEUE BUTTON PRESSED =====');
}
}