(tic-tac-toe): Starting work to implement "New Game" button
This commit is contained in:
parent
fc9e10f286
commit
ca9b2a7320
5 changed files with 31 additions and 3 deletions
|
|
@ -28,6 +28,8 @@ export interface ClientToServer {
|
||||||
gameMove: (up: GameMove) => void;
|
gameMove: (up: GameMove) => void;
|
||||||
keepalive: () => void;
|
keepalive: () => void;
|
||||||
connectedToGame: (gameId: string) => void;
|
connectedToGame: (gameId: string) => void;
|
||||||
|
// TODO
|
||||||
|
requestNewGame: () => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface ServerToClient {
|
export interface ServerToClient {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<div class="displaybox">
|
<div class="displaybox">
|
||||||
<div id="mainbox" class="mainboxDisplay">
|
<div id="mainbox" class="mainboxDisplay">
|
||||||
<button id="ttt-newgame-btn" class="btn-style absolute top-6 right-6">New Game</button>
|
<button id="NewGameBtn" class="btn-style absolute top-4 right-6">New Game</button>
|
||||||
<h1 class="text-3xl font-bold text-gray-800">
|
<h1 class="text-3xl font-bold text-gray-800">
|
||||||
Tic-tac-toe Box<span id="t-username"></span>
|
Tic-tac-toe Box<span id="t-username"></span>
|
||||||
</h1><br>
|
</h1><br>
|
||||||
|
|
|
||||||
|
|
@ -37,14 +37,30 @@ async function handleTTT(): Promise<RouteHandlerReturn> {
|
||||||
const socket: Socket = getSocket();
|
const socket: Socket = getSocket();
|
||||||
void socket;
|
void socket;
|
||||||
return {
|
return {
|
||||||
html: tttPage,
|
html: tttPage, postInsert: async (app) => {
|
||||||
postInsert: async (app) => {
|
|
||||||
if (!app) {
|
if (!app) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let user = await updateUser();
|
let user = await updateUser();
|
||||||
if (user === null)
|
if (user === null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
const newGameBtn = document.querySelector<HTMLButtonElement>("#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;
|
let curGame: CurrentGameInfo | null = null;
|
||||||
|
|
||||||
socket.on('updateInformation', (e) => showInfo(`UpdateInformation: t=${e.totalUser};q=${e.inQueue}`));
|
socket.on('updateInformation', (e) => showInfo(`UpdateInformation: t=${e.totalUser};q=${e.inQueue}`));
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ export interface ClientToServer {
|
||||||
gameMove: (up: GameMove) => void;
|
gameMove: (up: GameMove) => void;
|
||||||
keepalive: () => void;
|
keepalive: () => void;
|
||||||
connectedToGame: (gameId: string) => void;
|
connectedToGame: (gameId: string) => void;
|
||||||
|
requestNewGame: () => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface ServerToClient {
|
export interface ServerToClient {
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,8 @@ export class StateI {
|
||||||
socket.on('enqueue', () => this.enqueueUser(socket));
|
socket.on('enqueue', () => this.enqueueUser(socket));
|
||||||
socket.on('dequeue', () => this.dequeueUser(socket));
|
socket.on('dequeue', () => this.dequeueUser(socket));
|
||||||
socket.on('debugInfo', () => this.debugSocket(socket));
|
socket.on('debugInfo', () => this.debugSocket(socket));
|
||||||
|
// TODO
|
||||||
|
socket.on('requestNewGame', () => this.requestNewGame(socket));
|
||||||
|
|
||||||
socket.on('gameMove', (e) => this.gameMove(socket, e));
|
socket.on('gameMove', (e) => this.gameMove(socket, e));
|
||||||
socket.on('keepalive', () => this.keepAlive(socket));
|
socket.on('keepalive', () => this.keepAlive(socket));
|
||||||
|
|
@ -202,6 +204,13 @@ export class StateI {
|
||||||
|
|
||||||
game?.makeMove(socket.authUser.id, update.index);
|
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
|
// this value will be overriten
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue