This repository has been archived by the owner on Aug 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
79 lines (61 loc) · 1.89 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
// @ts-check
const fs = require("fs");
const { Client } = require("skribbler");
const words = (fs.readFileSync("./words.txt", "utf8").split(/\r?\n/));
if(words[0] === "") words.shift();
const host = new Client({
name: "Host",
createPrivateRoom: true
});
let member;
host.on("connected", () => {
console.log("Host connected to the room");
/**
* Set the max player count to 2
* Set the max draw time to 15
* Set the total amount of rounds to 14
* Set the total words the drawer can pick to 5
*/
host.updateRoomSettings("1", "2");
host.updateRoomSettings("2", "15");
host.updateRoomSettings("3", "14");
host.updateRoomSettings("4", "5");
console.log(`Lobby ID: ${host.lobbyId}`);
member = new Client({
name: "Member",
lobbyCode: host.lobbyId
});
member.on("connected", () => {
console.log("Member connected to the room, starting game.");
host.startGame();
main();
});
});
host.on("packet", ({id,data}) => {
if(id !== 11 || data.id !== 7) return;
console.log("Game over, starting a new game.");
host.startGame();
});
function main() {
host.on("chooseWord", (data) => {
console.log(`Host found words: ${data.join(", ")}.`);
for(const word of data) {
if(words.includes(word)) continue;
words.push(word);
}
host.selectWord(0);
member.sendMessage(data[0]);
});
member.on("chooseWord", (data) => {
console.log(`Member found words: ${data.join(", ")}.`);
for(const word of data) {
if(words.includes(word)) continue;
words.push(word);
}
member.selectWord(0);
host.sendMessage(data[0]);
});
}
setInterval(() => {
fs.writeFileSync("./words.txt", words.join("\n"));
}, 2500);