-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.js
executable file
·81 lines (73 loc) · 1.62 KB
/
model.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
console.log("Model loaded");
const model = (function() {
let isAlertOpened = false;
function alertUI(text, callback) {
isAlertOpened = true;
view.controls.enabled = false;
$("#dialog").text(text);
$("#dialog").dialog({
close: () => {
setTimeout(() => {
isAlertOpened = false;
view.controls.enabled = true;
callback();
}, 20);
}
});
}
if (/file/.test(location.href)) {
document.title = "[ТЕСТ] Сфериум";
}
if (localStorage.shown != "1") {
localStorage.shown = "1";
help();
}
function help() {
alertUI(settings.lang.hello, () => {});
}
function checkWin(state = view.getState()) {
for (let triplet of settings.winningTriplets) {
if (
state[triplet[0]] == 1 &&
state[triplet[1]] == 1 &&
state[triplet[2]] == 1
) {
return 1;
}
if (
state[triplet[0]] == 2 &&
state[triplet[1]] == 2 &&
state[triplet[2]] == 2
) {
return 2;
}
}
return -1;
}
let now;
refresh();
function onFaceClick(faceid) {
if (isAlertOpened) {
return;
}
if (view.getState()[faceid] != -1) {
return;
}
view.paintFace(faceid, now);
now = now == 1 ? 2 : 1;
let maybeWin = checkWin();
if (maybeWin == -1) {
return;
}
controller.stopClickMonitoring();
setTimeout(() => {
alertUI(settings.lang["winner" + maybeWin], refresh);
}, 40);
}
function refresh() {
now = 1;
controller.startClickMonitoring(onFaceClick);
view.reset();
}
return { refresh, help };
})();