From 74073a0a9bcffb37248a7d443e17cdd5928b5745 Mon Sep 17 00:00:00 2001 From: Andrew nuark G Date: Sun, 5 Mar 2023 11:42:01 +0700 Subject: [PATCH] Moving from JS 'String' to TS 'string' --- src/index.ts | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/src/index.ts b/src/index.ts index 10661de..4030e9a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -18,8 +18,8 @@ const io = new Server(server, { }); class Client { - private _login: String; - private _password: String; + private _login: string; + private _password: string; private _inGame: Boolean; public get login() { @@ -32,7 +32,7 @@ class Client { return this._inGame; } - constructor(login: String, password: String) { + constructor(login: string, password: string) { this._login = login; this._password = password; this._inGame = false; @@ -51,13 +51,13 @@ class Client { } class Game { - private id: String; + private id: string; private guesser: Client; private suggester: Client; private tries: number; - private guesses: Set; - private colors: Set; + private guesses: Set; + private colors: Set; public get Id() { return this.id; @@ -78,13 +78,13 @@ class Game { return this.colors; } - constructor(id: String, guesser: Client, suggester: Client, tries: number) { + constructor(id: string, guesser: Client, suggester: Client, tries: number) { this.id = id; this.guesser = guesser; this.suggester = suggester; this.tries = tries; - this.guesses = new Set(); - this.colors = new Set(); + this.guesses = new Set(); + this.colors = new Set(); while (this.colors.size < 6) { const key = availableColors[Math.floor(Math.random() * availableColors.length)]; @@ -99,7 +99,7 @@ class Game { return this.guesser; } - public Guess(player: Client, guess: String) { + public Guess(player: Client, guess: string) { if (this.guesses.has(guess)) { return true; } @@ -141,12 +141,12 @@ class Game { } class AvailableGame { - private _id: String; + private _id: string; private _player: Client; private _tries: number; - private _neededRole: String; + private _neededRole: string; - public get id(): String { + public get id(): string { return this._id; } public get player(): Client { @@ -155,11 +155,11 @@ class AvailableGame { public get tries(): number { return this._tries; } - public get neededRole(): String { + public get neededRole(): string { return this._neededRole; } - constructor(id: String, player: Client, tries: number, neededRole: String) { + constructor(id: string, player: Client, tries: number, neededRole: string) { this._id = id; this._player = player; this._tries = tries; @@ -178,8 +178,8 @@ class AvailableGame { let registeredClients: Client[] = []; let onlineClients: Map = new Map(); -let availableGames: Map = new Map(); -let runningGames: Map = new Map(); +let availableGames: Map = new Map(); +let runningGames: Map = new Map(); app.get("/", (req, res) => { res.send("

Hello world

"); @@ -300,7 +300,7 @@ function registerSocketLoggedInFunctions(socket: Socket) { }); } - function createGameEventHandler(tries: number, role: String): void { + function createGameEventHandler(tries: number, role: string): void { if (client.inGame) { socket.emit("createGameResponse", false, "Player is already in game"); return; @@ -328,7 +328,7 @@ function registerSocketLoggedInFunctions(socket: Socket) { io.emit("updateNeeded"); } - function joinGameEventHandler(gameId: String): void { + function joinGameEventHandler(gameId: string): void { const game = availableGames.get(gameId); if (game === undefined) { socket.emit("joinGameResponse", false, "Game does not exist"); @@ -373,7 +373,7 @@ function registerSocketLoggedInFunctions(socket: Socket) { runningGames.set(gameInfo.Id, gameInfo); } - function removeGameEventHandler(gameId: String): void { + function removeGameEventHandler(gameId: string): void { const game = availableGames.get(gameId); if (game === undefined) { socket.emit("removeGameResponse", false, "Game does not exist"); @@ -389,7 +389,7 @@ function registerSocketLoggedInFunctions(socket: Socket) { io.emit("updateNeeded"); } - function chatEventHandler(gameId: String, message: String): void { + function chatEventHandler(gameId: string, message: string): void { const game = runningGames.get(gameId); if (game === undefined || !client.inGame) { socket.emit("chatResponse", false, 400); @@ -417,7 +417,7 @@ function registerSocketLoggedInFunctions(socket: Socket) { }); } - function guessEventHandler(gameId: String, guess: String): void { + function guessEventHandler(gameId: string, guess: string): void { const game = runningGames.get(gameId); if (game === undefined || !client.inGame) { socket.emit("guessResponse", false, 400); @@ -465,7 +465,7 @@ function registerSocketLoggedInFunctions(socket: Socket) { } } - function leaveGameEventHandler(gameId: String): void { + function leaveGameEventHandler(gameId: string): void { const game = runningGames.get(gameId); if (game === undefined || !client.inGame) { socket.emit("guessResponse", false, 400);