Browse Source

add in-game status

master
nicolas-arnaud 2 years ago
parent
commit
a72da047ca
  1. 1
      back/volume/src/pong/game/Game.ts
  2. 1
      back/volume/src/pong/game/Player.ts
  3. 7
      back/volume/src/pong/pong.service.ts

1
back/volume/src/pong/game/Game.ts

@ -100,6 +100,7 @@ export class Game {
if (this.timer === null && this.players.length === 2) { if (this.timer === null && this.players.length === 2) {
this.ball = new Ball(new Point(this.map.size.x / 2, this.map.size.y / 2)) this.ball = new Ball(new Point(this.map.size.x / 2, this.map.size.y / 2))
this.players.forEach((p) => { this.players.forEach((p) => {
this.pongService.setInGame(p.name)
p.newGame() p.newGame()
}) })
this.playing = true this.playing = true

1
back/volume/src/pong/game/Player.ts

@ -32,5 +32,6 @@ export class Player {
newGame (): void { newGame (): void {
this.score = 0 this.score = 0
this.paddle = new Paddle(this.paddleCoords, this.mapSize) this.paddle = new Paddle(this.paddleCoords, this.mapSize)
} }
} }

7
back/volume/src/pong/pong.service.ts

@ -23,6 +23,13 @@ export class PongService {
player.winrate = (100 * player.wins) / player.matchs player.winrate = (100 * player.wins) / player.matchs
player.rank = (await this.usersService.getRank(player.ftId)) + 1 player.rank = (await this.usersService.getRank(player.ftId)) + 1
player.results.push(result) player.results.push(result)
player.status = "online"
await this.usersService.save(player)
}
async setInGame (playerName: string): Promise<void> {
const player = await this.usersService.findUserByName(playerName)
player.status = "in-game"
await this.usersService.save(player) await this.usersService.save(player)
} }

Loading…
Cancel
Save