feat(ttt): made proper queue and multi game handling
This commit is contained in:
parent
ed2b610f26
commit
972b78a1e2
7 changed files with 333 additions and 109 deletions
41
frontend/src/pages/ttt/socket.ts
Normal file
41
frontend/src/pages/ttt/socket.ts
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
import { type Socket } from 'socket.io-client';
|
||||
|
||||
export type UpdateInfo = {
|
||||
inQueue: number,
|
||||
totalUser: number,
|
||||
}
|
||||
export type CellState = 'X' | 'O' | null;
|
||||
|
||||
export type GameUpdate = {
|
||||
gameId: string;
|
||||
|
||||
playerX: string;
|
||||
playerO: string;
|
||||
|
||||
boardState: CellState[];
|
||||
currentPlayer: 'X' | 'O';
|
||||
gameState: 'winX' | 'winO' | 'concededX' | 'concededO' | 'draw' | 'ongoing';
|
||||
}
|
||||
|
||||
export type GameMove = {
|
||||
index: number;
|
||||
}
|
||||
export type GameMoveResponse = 'success' | 'invalidMove' | 'unknownError';
|
||||
|
||||
export interface ClientToServer {
|
||||
enqueue: () => void;
|
||||
dequeue: () => void;
|
||||
debugInfo: () => void;
|
||||
gameMove: (up: GameMove) => GameMoveResponse;
|
||||
};
|
||||
|
||||
export interface ServerToClient {
|
||||
forceDisconnect: (reason: string) => void;
|
||||
queueEvent: (msg: 'registered' | 'unregistered') => void;
|
||||
updateInformation: (info: UpdateInfo) => void,
|
||||
newGame: (gameId: string) => void,
|
||||
gameBoard: (state: GameUpdate) => void,
|
||||
};
|
||||
|
||||
export type SSocket = Socket<ClientToServer, ServerToClient>;
|
||||
export type CSocket = Socket<ServerToClient, ClientToServer>;
|
||||
Loading…
Add table
Add a link
Reference in a new issue