Skip to content

Commit

Permalink
show final score on game over screen
Browse files Browse the repository at this point in the history
  • Loading branch information
Sidney Klass authored and Sidney Klass committed Jan 17, 2020
1 parent deb86b1 commit 116848a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions game.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,13 @@ export default class PongGame {
checkGameOver() {
if (this.scorePlayer1 === 6) {
localStorage.setItem('winner', 'Spieler 1');
localStorage.setItem('gameResult', `{ "player1": ${this.scorePlayer1}, "player2": ${this.scorePlayer2}}`);
this.game.sound.play('GameSetMatch');
this.game.state.start('gameover');
}
if (this.scorePlayer2 === 6) {
localStorage.setItem('winner', 'Spieler 2');
localStorage.setItem('gameResult', `{ "player1": ${this.scorePlayer1}, "player2": ${this.scorePlayer2}}`);
this.game.sound.play('GameSetMatch');
this.game.state.start('gameover');
}
Expand Down
11 changes: 11 additions & 0 deletions gameOver.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,22 @@ export default class GameOver {
this.add.button(this.world.centerX - 80, 550, 'returnToHome', this.returnToHome,this, 2, 1, 0);
this.add.button(this.world.centerX - 80, 460, 'playAgain', this.playsameAgain,this, 2, 1, 0);
const winner = localStorage.getItem('winner');
const result = JSON.parse(localStorage.getItem('gameResult'));
result.player1
result.player2
this.game.add.text(80, 90, ` ${winner} \n hat gewonnen`, {
font: "48px Arial",
fill: "#fff",
algin: "center"
});
this.game.add.text(125, 255, `${result.player1} :`, {
font: "128px Arial",
fill: "#EC0909"
});
this.game.add.text(295, 255, result.player2, {
font: "128px Arial",
fill: "#EC0909",
});
}

update() {}
Expand Down

0 comments on commit 116848a

Please sign in to comment.