-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
208 lines (206 loc) · 7.04 KB
/
index.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
const statements = [
"Омегаверс", "Красный, как помидор", "Эвфемизмы", "Секс на N-дцат часов", "Флешбеки", "Кроссовер", "Избранный",
'Неожиданная смена пола ("сказал" -> "сказала")',
"Гейство", "Тупо повседневность", "Смайлики/Необычные символы", "Любовь с первого изнасилования",
"Извините, если есть ошибки", "Много многоточий", "Бедная нутрия!",
"Гг богат(а)/популярн(а)", "Пробелы перед знаками препинания",
"КАПС", "Описание локации в одно слово", "POV", "Абьюз", "Называть героев «-глазка», «-волоска»",
"Шмот/Лук/Было надето", "Точное время", "Кубики/Пресс", "Комментарии автора в скобочках",
"Мери Сью", "В ШОКЕ", "Точка в названии фанфика", "ГГ младше 18",
"Водные процедуры", "Родители умерли/уехали", "Т/и", '"з" вместо "c"', "Всё или НЕЧЕГО",
"Новенький(ая) в школе", "Лицо повествования меняется", "Ввод персонажа постредством столкновения с ГГ",
"В конце главы все отправляются спать", "Рост/вес персонажей", "НА РУЧКИ!", "Поетому/ето",
"Углубить поцелуй", "ИНГЛИШ", "Запятые не нужны", "Боксеры", "Первый раз", "Сказали хором",
"Мой первый фф, не судите строго", "Описание персонажей вначале", "Диалоги вида: первая буква имени и двоеточие",
"Попытка в графоманию (провальная)", "Худи и/или оверсайз",
"*Действие* (в звездочках)", "Клиффхэнгеры", "Попаданец", "Фанфик для Роскомнадзора"
]
let cells;
let bingoState;
let HEIGHT = 5;
let WIDTH = 5;
let seed;
window.onload = function() {
const url = new URL(window.location.href);
seed = url.searchParams.get("seed");
if (!seed) {
seed = uuidv4()
}
else {
document.getElementById("back-home-button").style.display = "block";
}
console.log(seed);
initTable(HEIGHT, WIDTH);
cells = document.getElementsByClassName("square");
Math.seedrandom(seed);
for(let i = 0; i < cells.length; ++i) {
const index = Math.floor(Math.random()*statements.length)
const randomStatements = statements[index];
cells[i].innerHTML = randomStatements;
statements.splice(index, 1);
}
}
function selectCell(element) {
const parseId = element.id.split("_");
const h = parseInt(parseId[1]);
const w = parseInt(parseId[2]);
const classList = [...element.classList]
if (classList.includes("active")){
element.classList = ["square"];
bingoState[h][w] = 0;
}
else {
element.classList.add("active");
bingoState[h][w] = 1;
}
let isBingo = checkBingo();
console.log("bingo:",isBingo);
if (isBingo) {
wonBingo()
}
}
function initTable(width, height) {
const bingoTable = document.getElementById("bingo_table");
bingoState = []
for (let h = 0; h < height; h++) {
bingoState[h] = [];
const tr = document.createElement("tr");
for (let w = 0; w < width; w++) {
bingoState[h][w] = 0;
const td = document.createElement("td");
td.classList = ["square"];
td.addEventListener( "click", function(e) {
selectCell(this);
});
td.id = `cell_${h}_${w}`
tr.appendChild(td);
}
bingoTable.appendChild(tr);
}
}
function checkBingo() {
let columnCounter = new Array(WIDTH);
for (let w = 0; w < WIDTH; w++) {
columnCounter[w] = 0;
}
let verticalCounter = 0;
let reverseVerticalCounter = 0;
let postageStampCounter = 0;
let outsideDiamondCounter = 0;
let insideDiamondCounter = 0;
let fourCorner = 0;
let insideFourCorner = 0;
let mid = (HEIGHT-1)/2;
for (let h = 0; h < HEIGHT; h++) {
let rowCounter = 0;
for (let w = 0; w < WIDTH; w++) {
if (bingoState[h][w] == 1){
rowCounter++;
columnCounter[w] += bingoState[h][w];
if (h == w) {
verticalCounter++;
}
if (h + w == HEIGHT - 1) {
reverseVerticalCounter++;
}
if (h < 2 && w >= WIDTH -2) {
postageStampCounter++;
}
if (
(h == 0 && w == mid)
|| (h == mid && (w == 0 || w == WIDTH -1))
|| (h == HEIGHT - 1 && w == mid)
){
outsideDiamondCounter++;
}
if (
(h == 1 && w == mid)
|| (h == mid && (w == 1 || w == WIDTH -2))
|| (h == HEIGHT - 2 && w == mid)
){
insideDiamondCounter++;
}
if (
(w == 0 && (h == 0 || h == HEIGHT-1))
|| (w == WIDTH-1 && (h == 0 || h == HEIGHT-1))
) {
fourCorner++;
}
if (
(w == mid - 1 && (h == mid -1 || h == mid + 1))
|| (w == mid + 1 && (h == mid - 1 || h == mid + 1))
) {
insideFourCorner++;
}
}
}
if (rowCounter == WIDTH) {
return true;
}
}
if (verticalCounter == HEIGHT) {
return true;
}
if (reverseVerticalCounter == HEIGHT) {
return true;
}
if (postageStampCounter == 4) {
return true;
}
if (outsideDiamondCounter == 4) {
return true;
}
if (insideDiamondCounter == 4) {
return true;
}
if (fourCorner == 4) {
return true;
}
if (insideFourCorner == 4) {
return true;
}
for (let w = 0; w < WIDTH; w++) {
if (columnCounter[w] == HEIGHT) {
return true;
}
}
return false
}
function wonBingo() {
const modalBg = document.querySelector('.modal-bg.bingo-win')
if (isBingo = true) {
modalBg.classList.add('bg-active')
}
}
function refreshThePage() {
location.reload();
}
function closeModal() {
const modalBg = document.querySelector('.modal-bg.bingo-win');
modalBg.classList = ["modal-bg"];
modalBg.classList.add('bingo-win');
}
function showInfo() {
const modalBg = document.querySelector('.modal-bg.info')
modalBg.classList.add('bg-active')
}
function closeInfo() {
const modalBg = document.querySelector('.modal-bg.info');
modalBg.classList = ["modal-bg"];
modalBg.classList.add('info');
}
function copySeed() {
const url = new URL(window.location.href);
const clipboard = navigator.clipboard;
const seedParam = url.searchParams.get("seed");
let copyURL = `${url}?seed=${seed}`;
if (seedParam) {
copyURL = url;
}
clipboard.writeText(copyURL);
const copyMessageElement = document.getElementById("copy-message");
copyMessageElement.classList.add("active");
setTimeout(function(){
copyMessageElement.classList = ["copy-message"];
}, 1500)
}