bug fixes
This commit is contained in:
@ -145,7 +145,7 @@ app.get("/api/reset/:sessionId", (req, res) => {
|
|||||||
const { sessionId } = req.params;
|
const { sessionId } = req.params;
|
||||||
|
|
||||||
db.run(`UPDATE "${sessionId}" SET state = 0 WHERE state = 1`);
|
db.run(`UPDATE "${sessionId}" SET state = 0 WHERE state = 1`);
|
||||||
db.run(`UPDATE "${sessionId}" SET ready = 0 WHERE ready = 1`);
|
//db.run(`UPDATE "${sessionId}" SET ready = 0 WHERE ready = 1`);
|
||||||
db.run(`UPDATE words SET inUse = 0 WHERE inUse = 1`);
|
db.run(`UPDATE words SET inUse = 0 WHERE inUse = 1`);
|
||||||
return res.status(201).json({ success: true });
|
return res.status(201).json({ success: true });
|
||||||
});
|
});
|
||||||
|
|||||||
18
game/game.js
18
game/game.js
@ -6,20 +6,20 @@ show_user()
|
|||||||
async function show_user() {
|
async function show_user() {
|
||||||
const res = await fetch(`/api/user/${sessionId}`);
|
const res = await fetch(`/api/user/${sessionId}`);
|
||||||
const users = await res.json();
|
const users = await res.json();
|
||||||
|
//todo: der check ob es schon einen imposter gibt sollte auf dem Server stattfinden!
|
||||||
const allUsers = users.map((u) => u.state);
|
const allUsers = users.map((u) => u.state);
|
||||||
if (allUsers.every((v) => v === 0)) {
|
if (allUsers.every((v) => v === 0)) {
|
||||||
createImposter();
|
createImposter();
|
||||||
async function createImposter() {
|
async function createImposter() {
|
||||||
const res = await fetch(`/api/${sessionId}/${username}/createImposter`);
|
const res = await fetch(`/api/${sessionId}/${username}/createImposter`);
|
||||||
var imposterStatus = getImposter(); //var für globale variable, muss in dieser funktion sein wegen komischer race condition bug
|
getImposter();
|
||||||
}
|
}
|
||||||
}else {
|
}else {
|
||||||
var imposterStatus = getImposter(); //var für globale variable, muss in dieser funktion sein wegen komischer race condition bug
|
getImposter();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//const imposterStatus = getImposter();
|
|
||||||
|
|
||||||
async function getImposter() {
|
async function getImposter() {
|
||||||
const res = await fetch(`/api/${sessionId}/${username}/getImposter`);
|
const res = await fetch(`/api/${sessionId}/${username}/getImposter`);
|
||||||
const stateObj = await res.json();
|
const stateObj = await res.json();
|
||||||
@ -30,20 +30,14 @@ async function getImposter() {
|
|||||||
if (state == 1) {
|
if (state == 1) {
|
||||||
console.log("du bist imposter");
|
console.log("du bist imposter");
|
||||||
ImposterStateDiv.textContent = "Du bist der Imposter!";
|
ImposterStateDiv.textContent = "Du bist der Imposter!";
|
||||||
return true;
|
getWords(true);
|
||||||
} else {
|
} else {
|
||||||
console.log("du bist kein imposter");
|
console.log("du bist kein imposter");
|
||||||
ImposterStateDiv.textContent = "Du bist kein Imposter!";
|
ImposterStateDiv.textContent = "Du bist kein Imposter!";
|
||||||
return false;
|
getWords(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialisierung: await getImposter(), dann getWords aufrufen
|
|
||||||
async function init() {
|
|
||||||
const imposterStatus = await getImposter();
|
|
||||||
await getWords(imposterStatus);
|
|
||||||
}
|
|
||||||
init();
|
|
||||||
|
|
||||||
async function getWords(imposterStatus) {
|
async function getWords(imposterStatus) {
|
||||||
const res = await fetch(`/api/getWords`);
|
const res = await fetch(`/api/getWords`);
|
||||||
|
|||||||
BIN
imposter.db
BIN
imposter.db
Binary file not shown.
13
index.html
13
index.html
@ -6,17 +6,18 @@
|
|||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>Imposter</title>
|
<title>Imposter</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
<h1 class="heading">IMPOSTER</h1>
|
||||||
<div>
|
<div>
|
||||||
<input id="username" placeholder="username">
|
<input id="username" class="username" placeholder="username">
|
||||||
<input id="session_id" placeholder = "session_id">
|
<input id="session_id" class="session_id" placeholder = "session_id">
|
||||||
<button onclick="re_direct()">send</button>
|
<button class ="joinButton"onclick="re_direct()">beitren</button>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<!-- <div>
|
||||||
<input id="word" placeholder="word">
|
<input id="word" placeholder="word">
|
||||||
<input id="imposterWord" placeholder="Imposter Wort">
|
<input id="imposterWord" placeholder="Imposter Wort">
|
||||||
<button onclick="addWord()">Wörter hinzufügen</button>
|
<button onclick="addWord()">Wörter hinzufügen</button>
|
||||||
</div>
|
</div> -->
|
||||||
<script src="index.js"></script>
|
<script src="index.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
@ -7,7 +7,8 @@
|
|||||||
background-color: white;
|
background-color: white;
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
border-width: 4px;
|
border-width: 4px;
|
||||||
max-width: 100px;
|
max-width: fit-content;
|
||||||
|
min-width: 100px;
|
||||||
margin: 5px auto;
|
margin: 5px auto;
|
||||||
font-size: 30px;
|
font-size: 30px;
|
||||||
|
|
||||||
|
|||||||
46
style.css
46
style.css
@ -1,3 +1,49 @@
|
|||||||
body {
|
body {
|
||||||
background-color: #09161E;
|
background-color: #09161E;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.username {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
background-color: white;
|
||||||
|
border-radius: 5px;
|
||||||
|
border-width: 4px;
|
||||||
|
max-width: fit-content;
|
||||||
|
min-width: 100px;
|
||||||
|
margin: 5px auto;
|
||||||
|
font-size: 30px;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
.session_id {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
background-color: white;
|
||||||
|
border-radius: 5px;
|
||||||
|
border-width: 4px;
|
||||||
|
max-width: fit-content;
|
||||||
|
min-width: 100px;
|
||||||
|
margin: 5px auto;
|
||||||
|
font-size: 30px;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
.joinButton {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
background-color: white;
|
||||||
|
border: 2px solid #ccc;
|
||||||
|
border-radius: 5px;
|
||||||
|
border-width: 4px;
|
||||||
|
max-width: fit-content;
|
||||||
|
margin: 100px auto;
|
||||||
|
font-size: 30px;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
.heading {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
font-size: 50px;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user