diff --git a/frontend/src/pages/ttt/socket.ts b/frontend/src/pages/ttt/socket.ts index 30ab897..a354195 100644 --- a/frontend/src/pages/ttt/socket.ts +++ b/frontend/src/pages/ttt/socket.ts @@ -28,6 +28,8 @@ export interface ClientToServer { gameMove: (up: GameMove) => void; keepalive: () => void; connectedToGame: (gameId: string) => void; + // TODO + requestNewGame: () => void; }; export interface ServerToClient { diff --git a/frontend/src/pages/ttt/ttt.html b/frontend/src/pages/ttt/ttt.html index e08114e..933bcf1 100644 --- a/frontend/src/pages/ttt/ttt.html +++ b/frontend/src/pages/ttt/ttt.html @@ -1,6 +1,6 @@
- +

Tic-tac-toe Box


diff --git a/frontend/src/pages/ttt/ttt.ts b/frontend/src/pages/ttt/ttt.ts index 6233713..8abf1b4 100644 --- a/frontend/src/pages/ttt/ttt.ts +++ b/frontend/src/pages/ttt/ttt.ts @@ -37,14 +37,30 @@ async function handleTTT(): Promise { const socket: Socket = getSocket(); void socket; return { - html: tttPage, - postInsert: async (app) => { + html: tttPage, postInsert: async (app) => { if (!app) { return; } let user = await updateUser(); if (user === null) return; + + const newGameBtn = document.querySelector("#NewGameBtn"); + + if (!newGameBtn) { + return showError('fatal error'); + } + + // TODO + // 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"); + }); + let curGame: CurrentGameInfo | null = null; socket.on('updateInformation', (e) => showInfo(`UpdateInformation: t=${e.totalUser};q=${e.inQueue}`)); diff --git a/src/tic-tac-toe/src/socket.ts b/src/tic-tac-toe/src/socket.ts index 45ce2ea..7b290f7 100644 --- a/src/tic-tac-toe/src/socket.ts +++ b/src/tic-tac-toe/src/socket.ts @@ -28,6 +28,7 @@ export interface ClientToServer { gameMove: (up: GameMove) => void; keepalive: () => void; connectedToGame: (gameId: string) => void; + requestNewGame: () => void; }; export interface ServerToClient { diff --git a/src/tic-tac-toe/src/state.ts b/src/tic-tac-toe/src/state.ts index 7ab2026..2e083ed 100644 --- a/src/tic-tac-toe/src/state.ts +++ b/src/tic-tac-toe/src/state.ts @@ -48,6 +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)); socket.on('gameMove', (e) => this.gameMove(socket, e)); socket.on('keepalive', () => this.keepAlive(socket)); @@ -202,6 +204,13 @@ export class StateI { game?.makeMove(socket.authUser.id, update.index); } + + // TODO + private requestNewGame(socket: SSocket) { + void socket; + // TODO + this.fastify.log.info('===== NEW GAME REQUESTED ====='); + } } // this value will be overriten