-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGame.js
63 lines (47 loc) · 2.39 KB
/
Game.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
class Game {
constructor(start) {
this.stats = new Statistics();
this.wallet = new Wallet(start);
document.getElementById('start').addEventListener('click', this.startGame.bind(this));
this.spanWallet = document.querySelector('.panel span.wallet');
this.boards = [...document.querySelectorAll('div.color')];
this.inputBid = document.getElementById('bid');
this.spanResult = document.querySelector('.score span.result');
this.spanGames = document.querySelector('.score span.number');
this.spanWins = document.querySelector('.score span.win');
this.spanLosses = document.querySelector('.score span.loss');
this.render()
}
render(colors = ['url(https://images.freeimages.com/images/large-previews/b7e/jamie-lee-1436054.jpg)', 'url(https://images.freeimages.com/images/large-previews/b7e/jamie-lee-1436054.jpg)', 'url(https://images.freeimages.com/images/large-previews/b7e/jamie-lee-1436054.jpg)'], money = this.wallet.getWalletValue(), result = "", stats = [0, 0, 0], bid = 0, wonMoney = 0) {
// console.log("gramy!!");
this.boards.forEach((board, i) => {
board.style.backgroundImage = colors[i]
})
this.spanWallet.textContent = money;
if (result) {
result = `Wygrałeś ${wonMoney}$. `;
} else if (!result && result !== "") {
result = `Przegrałeś ${bid}$. `
}
this.spanResult.textContent = result;
this.spanGames.textContent = stats[0];
this.spanWins.textContent = stats[1];
this.spanLosses.textContent = stats[2];
// this.inputBid.value = "";
}
startGame() {
if (this.inputBid.value < 1) return alert('Kwota, którą chcesz grać jest za mała!')
const bid = Math.floor(this.inputBid.value);
if (!this.wallet.checkCanPlay(bid)) {
return alert("masz za mało środków lub podana została nieprawidłowa wartość")
}
this.wallet.changeWallet(bid, '-');
this.draw = new Draw();
const colors = this.draw.getDrawResult();
const win = Result.checkWinner(colors);
const wonMoney = Result.moneyWinInGame(win, bid);
this.wallet.changeWallet(wonMoney);
this.stats.addGameToStatistics(win, bid);
this.render(colors, this.wallet.getWalletValue(), win, this.stats.showGameStatistics(), bid, wonMoney)
}
}