Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { Room, Delayed, Client } from 'colyseus';
import { type, Schema, MapSchema, ArraySchema } from '@colyseus/schema';
const TURN_TIMEOUT = 10
const BOARD_WIDTH = 3;
class State extends Schema {
@type("string") currentTurn: string;
@type({ map: "string" }) players = new MapSchema();
@type(["number"]) board: number[] = new ArraySchema(0, 0, 0, 0, 0, 0, 0, 0, 0);
@type("string") winner: string;
@type("boolean") draw: boolean;
}
export class TicTacToe extends Room {
maxClients = 2;
randomMoveTimeout: Delayed;
onCreate () {
this.setState(new State())
}
onJoin (client: Client) {
this.state.players[client.sessionId] = client.sessionId;
if (Object.keys(this.state.players).length === 2) {