-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAssigner.mjs
46 lines (38 loc) · 1.17 KB
/
Assigner.mjs
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
import { PAGES } from "./pages.mjs";
export class Assigner {
constructor(word, isSpy, assignersIterator) {
this.word = word;
this.isSpy = isSpy;
this.assignersIterator = assignersIterator;
}
invoke() {
document.querySelector("." + PAGES.assignPlayers).innerText = "";
const div = document.createElement("div");
div.className = "assigner";
const p = document.createElement("p");
p.innerText = "Press `OK` to continue";
div.appendChild(p);
const button = document.createElement("button");
button.innerText = "OK";
button.onclick = () => {
this.showWord(p, button);
};
div.appendChild(button);
document.querySelector("." + PAGES.assignPlayers).appendChild(div);
}
showWord(paragraphDom, okButtonDom) {
if (!this.isSpy) {
paragraphDom.innerText = this.word;
} else {
paragraphDom.innerText = "شما جاسوس هستید!!";
}
okButtonDom.onclick = () => {
const nextAssigner = this.assignersIterator.next().value;
if (nextAssigner) {
nextAssigner.invoke();
} else {
window.showTimer();
}
};
}
}