Add Players with JoinLobby

landing-page-layout
Laura Valera 2025-02-04 20:35:30 +01:00
parent 3a9b88ef55
commit e323623007
2 changed files with 14 additions and 1 deletions

View File

@ -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');
} }
} }

View File

@ -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()]);
} }
} }