-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame.js
More file actions
61 lines (56 loc) · 1.93 KB
/
Copy pathgame.js
File metadata and controls
61 lines (56 loc) · 1.93 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
var list = [];
var i = 0;
var N = getQueryStringValue('N');
var spy_index = Math.round(1+(N-1)*Math.random());
var word_index = null;
var played = [];
var boolean = true;
document.getElementById("nGiocatori").innerHTML = N;
async function newGame(){
i = 0;
spy_index = Math.round(1+(N-1)*Math.random());
word_index = null;
const response = await fetch('list.txt');
const fileContent = await response.text();
list = fileContent.split('\n').map(line => line.trim());
if(list.length > played.length) {
do {
word_index = Math.round((list.length-1)*Math.random());
} while (played.includes(word_index));
played.push(word_index);
document.getElementById("buttons").style.display = "flex";
document.getElementById("newGameId").style.display = "none";
document.getElementById("titleID").innerHTML = "Partita in corso...";
} else {
document.getElementById("newGameId").style.display = "none";
document.getElementById("titleID").innerHTML = "Parole terminate, ricarica la pagina!";
};
}
// Funzione per ottenere il valore di un parametro dalla query string
function getQueryStringValue(key) {
var urlParams = new URLSearchParams(window.location.search);
return urlParams.get(key);
}
function show() {
if (boolean) {
boolean = false;
el = document.getElementById("input-text-ID");
if (i+1 == spy_index){
el.innerHTML = "Spia!";
} else {
el.innerHTML = list[word_index];
}
i = i+1;
el.style.display = "block";
}
}
function hide() {
boolean = true;
el = document.getElementById("input-text-ID");
el.style.display = "none";
if (i == N){
document.getElementById("titleID").innerHTML = "Tutti hanno il ruolo!";
document.getElementById("buttons").style.display = "none";
document.getElementById("newGameId").style.display = "flex";
}
}