Add Players with JoinLobby
parent
3a9b88ef55
commit
e323623007
|
|
@ -40,6 +40,10 @@ export class AppService implements OnGatewayConnection {
|
||||||
@MessageBody() event: JoinLobbyEvent,
|
@MessageBody() event: JoinLobbyEvent,
|
||||||
) {
|
) {
|
||||||
this.playerService.addUserName(client.id, event.userName);
|
this.playerService.addUserName(client.id, event.userName);
|
||||||
|
this.gameService.joinGame(
|
||||||
|
this.playerService.getPlayer(client.id),
|
||||||
|
event.lobbyId,
|
||||||
|
);
|
||||||
this.logger.log('Te has unido a un lobby');
|
this.logger.log('Te has unido a un lobby');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,16 @@ export class GameService {
|
||||||
const gameId = uuidv4();
|
const gameId = uuidv4();
|
||||||
const gameCode = uuidv4().slice(-5).toUpperCase();
|
const gameCode = uuidv4().slice(-5).toUpperCase();
|
||||||
const game: Game = new Game(gameId, gameCode, player);
|
const game: Game = new Game(gameId, gameCode, player);
|
||||||
this.games.set(gameId, game);
|
this.games.set(gameCode, game);
|
||||||
|
this.logger.log([...this.games.entries()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
joinGame(player: Player, gameCode: string) {
|
||||||
|
const game = this.games.get(gameCode);
|
||||||
|
if (game === undefined) {
|
||||||
|
throw Error('No se ha encontrado el Lobby');
|
||||||
|
}
|
||||||
|
game.players.push(player);
|
||||||
this.logger.log([...this.games.entries()]);
|
this.logger.log([...this.games.entries()]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue