startgame in js

This commit is contained in:
Djalim Simaila 2023-01-10 13:34:47 +01:00
parent 86ee9c3863
commit 1addd381a3
4 changed files with 33 additions and 1 deletions

View File

@ -0,0 +1,17 @@
async function makeAPIRequest(endpoint, body){
return new Promise((resolve, reject)=>{
const fetchOptions = {
method: "POST",
body: new URLSearchParams(body)
}
fetch("/api/v1/"+endpoint, fetchOptions).then(resp => {
resp.json().then(jsonResp=>{
if(jsonResp["error"] == 0){
resolve(jsonResp)
}else{
reject(endpoint+": "+jsonResp["msg"])
}
});
})
})
}

View File

@ -125,7 +125,7 @@ function createMultiPlayerRoom() {
hideInvalidInputErrorMessage();
//TODO: code to create multi player game
startGame()
}
function joinMultiPlayerRoom() {
@ -208,6 +208,16 @@ function changeTheme() {
}
}
async function startGame(){
username = document.getElementById("game_username").value;
let data = {}
data["username"] = username
await makeAPIRequest("createGame",data);
}
async function joinGame(){
username = document.getElementById("game_username").value();
gameid = document.getElementById("game_room_code").value();
}
// Set event listeners
document.getElementById("play_button").addEventListener("click", showGameModeSelection);

View File

@ -72,6 +72,8 @@
<a href="/legal" class="footer_link link" target="_blank" title="Consulter les mentions légales de Truth Inquiry (ouverture dans un nouvel onglet)">Mentions légales</a>
</div>
</footer>
<script src="/static/js/api.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.4.1/socket.io.min.js"></script>
<script src="/static/js/game_common.js"></script>
<script src="/static/js/game_start_page.js"></script>
</body>

View File

@ -61,7 +61,10 @@
</div>
</div>
</noscript>
<script src="/static/js/api.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.4.1/socket.io.min.js"></script>
<script src="/static/js/game_common.js"></script>
<script src="/static/js/game_lobby.js"></script>
</body>
</html>