-
Notifications
You must be signed in to change notification settings - Fork 1
/
Interface.js
139 lines (110 loc) · 3.4 KB
/
Interface.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
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
class Interface {
constructor() {
this._gameBtn = document.getElementById("start-stop");
this._resetBtn = document.getElementById("reset");
this._difficultySelect = document.getElementById("difficulty-select");
this._nameInput = document.getElementById("username-input");
this._nameBtn = document.getElementById("username-button");
this._usename = this.nameInput.value;
this._timer = document.getElementById("timer");
this._actionsCounter = document.getElementById("actions");
this._info = document.querySelector("info");
}
get gameBtn() {
return this._gameBtn;
}
set gameBtn(gameBtn) {
return (this._gameBtn = gameBtn);
}
get resetBtn() {
return this._resetBtn;
}
set resetBtn(resetBtn) {
return (this._resetBtn = resetBtn);
}
get difficultySelect() {
return this._difficultySelect;
}
set difficultySelect(difficultySelect) {
return (this._difficultySelect = difficultySelect);
}
get nameInput() {
return this._nameInput;
}
set nameInput(nameInput) {
return (this._nameInput = nameInput);
}
get nameBtn() {
return this._nameBtn;
}
set nameBtn(nameBtn) {
return (this._nameBtn = nameBtn);
}
get usename() {
return this._usename;
}
set usename(usename) {
return (this._usename = usename);
}
get timer() {
return this._timer;
}
set timer(timer) {
return (this._timer = timer);
}
get actionsCounter() {
return this._actionsCounter;
}
set actionsCounter(actionsCounter) {
return (this._actionsCounter.textContent = actionsCounter);
}
get info() {
return this._info;
}
set info(info) {
return (this._info = info);
}
changeGameBtn(type = "stop") {
this.gameBtn.dataset.game = type;
this.gameBtn.style.backgroundColor = type === "stop" ? "red" : "green";
this.gameBtn.textContent = type.toUpperCase();
}
toggleGameBtn() {
return this.gameBtn.dataset.game === "start" ? this.changeGameBtn() : this.changeGameBtn("start");
}
addGameSummary(time, actions, restartCallback, grid, timer, counter, binded, container = document.body) {
const summaryPopup = document.createElement('div');
summaryPopup.innerHTML = `
<h1>Win!</h1>
<h2>Time: ${time}</h2>
<h3>Number of actions: ${actions}</h3>
`;
container.style.position = 'relative';
summaryPopup.style.width = '600px';
summaryPopup.style.height = '300px';
summaryPopup.style.position = 'absolute';
summaryPopup.style.top = '50%';
summaryPopup.style.left = '50%';
summaryPopup.style.transform = 'translate(-50%, -50%)';
summaryPopup.style.color = '#fffff';
summaryPopup.style.backgroundColor = 'green';
summaryPopup.style.textAlign = 'center';
summaryPopup.id = 'summary-popup';
const btn = document.createElement('button');
btn.textContent = 'NEW GAME';
btn.id = 'new-game-btn';
btn.className = 'btn';
btn.style.backgroundColor = 'red';
summaryPopup.appendChild(btn);
container.appendChild(summaryPopup);
const btnHtml = document.getElementById('new-game-btn');
btnHtml.addEventListener('click', () => {
restartCallback.call(binded, grid, timer, counter);
this.removeGameSummary();
if (this.gameBtn.dataset.game === 'stop') this.changeGameBtn('start');
});
}
removeGameSummary(elem = document.getElementById('summary-popup')) {
elem.parentNode.removeChild(elem);
}
}