From 6a0d413023a893f9ca56b205df24ee7ed46b501e Mon Sep 17 00:00:00 2001 From: unige Date: Tue, 15 Sep 2020 12:37:33 +0300 Subject: [PATCH] Added Win amount to the Scoreboard --- src/core/Scoreboard.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/core/Scoreboard.ts b/src/core/Scoreboard.ts index 194cbd5..3bdc6cb 100644 --- a/src/core/Scoreboard.ts +++ b/src/core/Scoreboard.ts @@ -3,7 +3,9 @@ import * as PIXI from 'pixi.js'; export default class Scoreboard { public container: PIXI.Container; public outOfMoney = false; + private winAmountText: PIXI.Text; private moneyText: PIXI.Text; + private winAmount: number = 0; private money: number = 100; private bet: number = 5; @@ -25,6 +27,8 @@ export default class Scoreboard { increment() { this.money += this.bet * 2; this.moneyText.text = `money: $${this.money}`; + this.winAmount += this.bet; + this.winAmountText.text = `win: $${this.winAmount}`; if (this.outOfMoney) this.outOfMoney = false; } @@ -41,15 +45,19 @@ export default class Scoreboard { const betText = new PIXI.Text(`bet: $${this.bet}`, style); betText.y = this.moneyText.height + 10; - betText.x = this.moneyText.x = 10; + this.winAmountText = new PIXI.Text(`win: $${this.winAmount}`, style); + this.winAmountText.y = betText.y + betText.height + 5; + + betText.x = this.moneyText.x = this.winAmountText.x = 10; const rect = new PIXI.Graphics(); rect.beginFill(0x02474E, 0.8); - rect.drawRect(0, 0, 160, this.moneyText.height + betText.height + 20); + const rectHeight = this.moneyText.height + betText.height + this.winAmountText.height + 25; + rect.drawRect(0, 0, 160, rectHeight); rect.endFill(); this.container.x = appWidth - rect.width - 7; this.container.y = appHeight / 2 + 70; - this.container.addChild(rect, this.moneyText, betText); + this.container.addChild(rect, this.moneyText, betText, this.winAmountText); } }