Moving from JS 'String' to TS 'string'
This commit is contained in:
parent
c19d04ad1a
commit
74073a0a9b
1 changed files with 23 additions and 23 deletions
46
src/index.ts
46
src/index.ts
|
|
@ -18,8 +18,8 @@ const io = new Server(server, {
|
||||||
});
|
});
|
||||||
|
|
||||||
class Client {
|
class Client {
|
||||||
private _login: String;
|
private _login: string;
|
||||||
private _password: String;
|
private _password: string;
|
||||||
private _inGame: Boolean;
|
private _inGame: Boolean;
|
||||||
|
|
||||||
public get login() {
|
public get login() {
|
||||||
|
|
@ -32,7 +32,7 @@ class Client {
|
||||||
return this._inGame;
|
return this._inGame;
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(login: String, password: String) {
|
constructor(login: string, password: string) {
|
||||||
this._login = login;
|
this._login = login;
|
||||||
this._password = password;
|
this._password = password;
|
||||||
this._inGame = false;
|
this._inGame = false;
|
||||||
|
|
@ -51,13 +51,13 @@ class Client {
|
||||||
}
|
}
|
||||||
|
|
||||||
class Game {
|
class Game {
|
||||||
private id: String;
|
private id: string;
|
||||||
private guesser: Client;
|
private guesser: Client;
|
||||||
private suggester: Client;
|
private suggester: Client;
|
||||||
private tries: number;
|
private tries: number;
|
||||||
|
|
||||||
private guesses: Set<String>;
|
private guesses: Set<string>;
|
||||||
private colors: Set<String>;
|
private colors: Set<string>;
|
||||||
|
|
||||||
public get Id() {
|
public get Id() {
|
||||||
return this.id;
|
return this.id;
|
||||||
|
|
@ -78,13 +78,13 @@ class Game {
|
||||||
return this.colors;
|
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.id = id;
|
||||||
this.guesser = guesser;
|
this.guesser = guesser;
|
||||||
this.suggester = suggester;
|
this.suggester = suggester;
|
||||||
this.tries = tries;
|
this.tries = tries;
|
||||||
this.guesses = new Set<String>();
|
this.guesses = new Set<string>();
|
||||||
this.colors = new Set<String>();
|
this.colors = new Set<string>();
|
||||||
|
|
||||||
while (this.colors.size < 6) {
|
while (this.colors.size < 6) {
|
||||||
const key = availableColors[Math.floor(Math.random() * availableColors.length)];
|
const key = availableColors[Math.floor(Math.random() * availableColors.length)];
|
||||||
|
|
@ -99,7 +99,7 @@ class Game {
|
||||||
return this.guesser;
|
return this.guesser;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Guess(player: Client, guess: String) {
|
public Guess(player: Client, guess: string) {
|
||||||
if (this.guesses.has(guess)) {
|
if (this.guesses.has(guess)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -141,12 +141,12 @@ class Game {
|
||||||
}
|
}
|
||||||
|
|
||||||
class AvailableGame {
|
class AvailableGame {
|
||||||
private _id: String;
|
private _id: string;
|
||||||
private _player: Client;
|
private _player: Client;
|
||||||
private _tries: number;
|
private _tries: number;
|
||||||
private _neededRole: String;
|
private _neededRole: string;
|
||||||
|
|
||||||
public get id(): String {
|
public get id(): string {
|
||||||
return this._id;
|
return this._id;
|
||||||
}
|
}
|
||||||
public get player(): Client {
|
public get player(): Client {
|
||||||
|
|
@ -155,11 +155,11 @@ class AvailableGame {
|
||||||
public get tries(): number {
|
public get tries(): number {
|
||||||
return this._tries;
|
return this._tries;
|
||||||
}
|
}
|
||||||
public get neededRole(): String {
|
public get neededRole(): string {
|
||||||
return this._neededRole;
|
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._id = id;
|
||||||
this._player = player;
|
this._player = player;
|
||||||
this._tries = tries;
|
this._tries = tries;
|
||||||
|
|
@ -178,8 +178,8 @@ class AvailableGame {
|
||||||
|
|
||||||
let registeredClients: Client[] = [];
|
let registeredClients: Client[] = [];
|
||||||
let onlineClients: Map<Socket, Client> = new Map<Socket, Client>();
|
let onlineClients: Map<Socket, Client> = new Map<Socket, Client>();
|
||||||
let availableGames: Map<String, AvailableGame> = new Map<String, AvailableGame>();
|
let availableGames: Map<string, AvailableGame> = new Map<string, AvailableGame>();
|
||||||
let runningGames: Map<String, Game> = new Map<String, Game>();
|
let runningGames: Map<string, Game> = new Map<string, Game>();
|
||||||
|
|
||||||
app.get("/", (req, res) => {
|
app.get("/", (req, res) => {
|
||||||
res.send("<h1>Hello world</h1>");
|
res.send("<h1>Hello world</h1>");
|
||||||
|
|
@ -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) {
|
if (client.inGame) {
|
||||||
socket.emit("createGameResponse", false, "Player is already in game");
|
socket.emit("createGameResponse", false, "Player is already in game");
|
||||||
return;
|
return;
|
||||||
|
|
@ -328,7 +328,7 @@ function registerSocketLoggedInFunctions(socket: Socket) {
|
||||||
io.emit("updateNeeded");
|
io.emit("updateNeeded");
|
||||||
}
|
}
|
||||||
|
|
||||||
function joinGameEventHandler(gameId: String): void {
|
function joinGameEventHandler(gameId: string): void {
|
||||||
const game = availableGames.get(gameId);
|
const game = availableGames.get(gameId);
|
||||||
if (game === undefined) {
|
if (game === undefined) {
|
||||||
socket.emit("joinGameResponse", false, "Game does not exist");
|
socket.emit("joinGameResponse", false, "Game does not exist");
|
||||||
|
|
@ -373,7 +373,7 @@ function registerSocketLoggedInFunctions(socket: Socket) {
|
||||||
runningGames.set(gameInfo.Id, gameInfo);
|
runningGames.set(gameInfo.Id, gameInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeGameEventHandler(gameId: String): void {
|
function removeGameEventHandler(gameId: string): void {
|
||||||
const game = availableGames.get(gameId);
|
const game = availableGames.get(gameId);
|
||||||
if (game === undefined) {
|
if (game === undefined) {
|
||||||
socket.emit("removeGameResponse", false, "Game does not exist");
|
socket.emit("removeGameResponse", false, "Game does not exist");
|
||||||
|
|
@ -389,7 +389,7 @@ function registerSocketLoggedInFunctions(socket: Socket) {
|
||||||
io.emit("updateNeeded");
|
io.emit("updateNeeded");
|
||||||
}
|
}
|
||||||
|
|
||||||
function chatEventHandler(gameId: String, message: String): void {
|
function chatEventHandler(gameId: string, message: string): void {
|
||||||
const game = runningGames.get(gameId);
|
const game = runningGames.get(gameId);
|
||||||
if (game === undefined || !client.inGame) {
|
if (game === undefined || !client.inGame) {
|
||||||
socket.emit("chatResponse", false, 400);
|
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);
|
const game = runningGames.get(gameId);
|
||||||
if (game === undefined || !client.inGame) {
|
if (game === undefined || !client.inGame) {
|
||||||
socket.emit("guessResponse", false, 400);
|
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);
|
const game = runningGames.get(gameId);
|
||||||
if (game === undefined || !client.inGame) {
|
if (game === undefined || !client.inGame) {
|
||||||
socket.emit("guessResponse", false, 400);
|
socket.emit("guessResponse", false, 400);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue