diff --git a/srcs/requirements/svelte/api_front/src/pages/game/Game.svelte b/srcs/requirements/svelte/api_front/src/pages/game/Game.svelte index 224be713..091a3741 100644 --- a/srcs/requirements/svelte/api_front/src/pages/game/Game.svelte +++ b/srcs/requirements/svelte/api_front/src/pages/game/Game.svelte @@ -34,10 +34,11 @@ let token = ""; //Game's stuff gameserver side - let sound = "on"; // possible de faire un boolean avec svelte et radio buttons ? + let sound = ""; let multi_balls = false; let moving_walls = false; - let matchOptions : enumeration.MatchOptions = enumeration.MatchOptions.noOption; + let matchOption : enumeration.MatchOptions = enumeration.MatchOptions.noOption; + //html boolean for pages let showWaitPage = false; let showInvitations = false; @@ -60,17 +61,71 @@ }) const init = async() => { + optionsAreNotSet = false + showWaitPage = true + console.log("Player two username " + playerTwoUsername) if (multi_balls === true) matchOption |= enumeration.MatchOptions.multiBalls if (moving_walls === true ) matchOption |= enumeration.MatchOptions.movingWalls - initAudio(sound) - initMatchOptions(matchOption) - optionsAreNotSet = false - initPong(new GameArea()) - initGc(new GameComponentsClient(matchOption, pong.ctx)) - initStartFunction(start) - initWebSocket(matchOption) + const res = await fetch("http://transcendance:8080/api/v2/game/ticket", { + method : "POST", + headers : {'Content-Type': 'application/json'}, + body : JSON.stringify({ + playerOneUsername : user.username, + playerTwoUsername : playerTwoUsername, + gameOptions : matchOption, + isGameIsWithInvitation : invite_someone + }) + }) + .then(x => x.json()) + .catch(error => { + console.log(error) + }) + if (res.status === 403 || res.status === 404 || res.status === 500) + { + errorMessageWhenAttemptingToGetATicket = res.message; + showError = true; + setTimeout(() => { + showError = false; + showWaitPage = false + optionsAreNotSet = true + playerTwoUsername = ""; + matchOption = 0; + token = "" + }, 5000) + return ; + } + else if (res.status === 200) + { + initAudio(sound) + initMatchOptions(matchOption) + initPong(new GameArea()) + initGc(new GameComponentsClient(matchOption, pong.ctx)) + initStartFunction(start) + initWebSocket(matchOption) + } + // const fetch = await fetch("http://transcendance:8080/api/v2/game/gameServer/validate", { + // method : "POST", + // headers : {'Content-Type': 'application/json'}, + // body : JSON.stringify({ + // playerOneUsername : user.username, + // playerTwoUsername : playerTwoUsername, + // gameOptions : matchOption, + // isGameIsWithInvitation : invite_someone, + // token : token + // }) + // }) + // .then(x => x.json()) + // .catch(error => { + // console.log(error) + // }) + // if (res.status !== 200) + // { + // showError = true; + // errorMessageWhenAttemptingToGetATicket = "Your session is not valid. Please try again." + // return ; + // } } function start() : void { @@ -133,35 +188,83 @@
move up: 'w' or 'up arrow'
-move down: 's' OR 'down arrow'
-grid on/off: 'g'
+ {#if showError === true} +