game function complete
This commit is contained in:
@ -8,6 +8,9 @@
|
||||
<title>game</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="imposterState" class="imposterState"></div>
|
||||
<div id="word" class="word"></div>
|
||||
|
||||
<script src="./game.js" ></script>
|
||||
</body>
|
||||
</html>
|
||||
28
game/game.js
28
game/game.js
@ -18,14 +18,40 @@ async function show_user() {
|
||||
}
|
||||
}
|
||||
|
||||
const imposterStatus = getImposter();
|
||||
|
||||
async function getImposter() {
|
||||
const res = await fetch(`/api/${sessionId}/${username}/getImposter`);
|
||||
const stateObj = await res.json();
|
||||
state = stateObj.state;
|
||||
|
||||
const ImposterStateDiv = document.getElementById('imposterState');
|
||||
|
||||
if (state == 1) {
|
||||
console.log("du bist imposter");
|
||||
ImposterStateDiv.textContent = 'Du bist der Imposter!'
|
||||
return true
|
||||
} else {
|
||||
console.log("du bist kein imposter");
|
||||
ImposterStateDiv.textContent = 'Du bist kein Imposter!'
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
getWords(imposterStatus)
|
||||
|
||||
async function getWords(imposterStatus) {
|
||||
const res = await fetch(`/api/getWords`);
|
||||
const words = await res.json();
|
||||
console.log(words);
|
||||
const WordDiv = document.getElementById('word');
|
||||
if (res.status == 201){
|
||||
getWords();
|
||||
} else if (imposterStatus) {
|
||||
console.log(words.imposterWord)
|
||||
WordDiv.textContent = "dein tip:" + words.imposterWord;
|
||||
}else if (!imposterStatus){
|
||||
console.log(words.word)
|
||||
WordDiv.textContent = "dein wort:" + words.word;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,3 +1,25 @@
|
||||
body {
|
||||
background-color: #09161e;
|
||||
}
|
||||
.imposterState{
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
background-color: white;
|
||||
border-radius: 5px;
|
||||
border-width: 4px;
|
||||
max-width: fit-content;
|
||||
margin: 5px auto;
|
||||
font-size: 30px;
|
||||
|
||||
}
|
||||
.word {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
background-color: white;
|
||||
border-radius: 5px;
|
||||
border-width: 4px;
|
||||
max-width: fit-content;
|
||||
margin: 5px auto;
|
||||
font-size: 30px;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user