-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathValuesBoard.ts
More file actions
149 lines (127 loc) · 4.8 KB
/
Copy pathValuesBoard.ts
File metadata and controls
149 lines (127 loc) · 4.8 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import { SETTINGS } from "./Settings";
import { board, travel, Position, changeTravel, keydown, keyup, gameStart } from "./index";
import { checkGameStart, gameEnd, gameLost } from "./functions";
export class ValuesBoard {
pointsPerNextLevel: number = SETTINGS.levelClear;
pointValue: number = SETTINGS.scoreForPoint;
points: number = 0;
timer: number = SETTINGS.timerStart;
score: number = 0;
numbersPanel: HTMLElement | null = document.getElementById("numbersPanel") as HTMLElement;
pointsPerNextLevelDiv: HTMLElement = document.getElementById("pointsPerNextLevel") as HTMLElement;
pointValueDiv: HTMLElement = document.getElementById("pointValue") as HTMLElement;
pointsDiv: HTMLElement = document.getElementById("points") as HTMLElement;
timerDiv: HTMLElement = document.getElementById("timer") as HTMLElement;
scoreDiv: HTMLElement = document.getElementById("score") as HTMLElement;
gameLostDiv: HTMLElement = document.getElementById("gameLost") as HTMLElement;
interval: NodeJS.Timer = setInterval(() => { });
constructor() {
this.showPanel();
this.asignValues();
this.timerChangeValue();
}
showPanel = () => {
this.gameLostDiv.style.display = "none"
this.gameLostDiv.style.color = "red"
this.gameLostDiv.innerHTML = ""
}
asignValues = () => {
this.printValues();
}
addPoint = () => {
this.points++;
this.score = this.points * this.pointValue
if (this.points == this.pointsPerNextLevel) {
board.openExit();
var audio = new Audio('sounds/open-gate.mp3');
audio.play();
}
}
printValues = () => {
this.pointsPerNextLevelDiv.innerHTML = "" + this.pointsPerNextLevel + ""
this.pointValueDiv.innerHTML = "" + this.pointValue + ""
this.pointsDiv.innerHTML = "" + this.checkFormat(this.points, 3) + ""
this.timerDiv.innerHTML = "" + this.checkFormat(this.timer, 3) + ""
this.scoreDiv.innerHTML = "" + this.checkFormat(this.score, 6) + ""
}
checkFormat = (number: number, nODigits: number) => {
let numStr = JSON.stringify(number)
if (numStr.length != nODigits) {
let howMuch0 = 0;
howMuch0 = nODigits - numStr.length
for (let i = 0; i < howMuch0; i++) {
numStr = "" + 0 + "" + numStr
}
}
return numStr;
}
timerChangeValue = () => {
// return 0
this.interval = setInterval(async () => {
this.timer--;
this.printValues();
if (this.timer == 0) {
// clearInterval(this.interval)
console.log("przegrana - koniec czasu");
this.lostByTime();
}
}, 1000)
}
lostByTime = async () => {
gameEnd()
const gameLostDiv = document.getElementById("gameLost") as HTMLElement
let position: Position;
for (let i = 0; i < 5; i++) {
gameLostDiv.style.display = "block"
gameLostDiv.innerHTML = "OUT OF TIME"
await this.timeout(1000)
gameLostDiv.style.display = "none"
await this.timeout(1000)
}
await this.timeout(500)
position = await board.getPosition();
this.destroyAround(position.i, position.j)
var audio = new Audio('sounds/stone-fall.mp3');
audio.play();
await this.timeout(1000)
gameLost();
console.table(SETTINGS.boardBackup)
await checkGameStart();
}
destroyAround = (i: number, j: number) => {
SETTINGS.board[i][j] = ""
SETTINGS.board[i + 1][j + 1] = ""
SETTINGS.board[i + 1][j - 1] = ""
SETTINGS.board[i + 1][j] = ""
SETTINGS.board[i][j + 1] = ""
SETTINGS.board[i][j - 1] = ""
SETTINGS.board[i - 1][j + 1] = ""
SETTINGS.board[i - 1][j - 1] = ""
SETTINGS.board[i - 1][j] = ""
board.create();
}
timeout = (ms: number) => {
return new Promise(resolve => setTimeout(resolve, ms))
}
giveTimePoints = async () => {
// this.timer;
const myInterval = setInterval(async () => {
this.timer--;
this.score++;
this.printValues();
if (this.timer == 0) {
clearInterval(myInterval)
}
}, 15)
await this.timeout(5000)
const gameLostDiv = document.getElementById("gameLost") as HTMLElement
for (let i = 0; i < 5; i++) {
gameLostDiv.style.display = "block"
gameLostDiv.style.backgroundColor = "gold"
gameLostDiv.innerHTML = "congrats, you won :)))"
await this.timeout(1000)
gameLostDiv.style.display = "none"
await this.timeout(1000)
}
}
}