diff --git a/srcs/requirements/game_server/game_back/src/server/class/GameSession.ts b/srcs/requirements/game_server/game_back/src/server/class/GameSession.ts
index 4a4446ac..38d0039c 100644
--- a/srcs/requirements/game_server/game_back/src/server/class/GameSession.ts
+++ b/srcs/requirements/game_server/game_back/src/server/class/GameSession.ts
@@ -229,8 +229,7 @@ export class GameSession {
this._forfeit();
}
else {
- // WIP: envoyer un truc à Nest ? Genre "match draw"
- this.destroy();
+ this._matchEnd(en.PlayerSide.noSide, true);
}
return true;
}
@@ -269,11 +268,16 @@ export class GameSession {
gc.scoreLeft = 3;
gc.scoreRight = 0;
}
- else
+ else if (winner === en.PlayerSide.right)
{
gc.scoreLeft = 0;
gc.scoreRight = 3;
}
+ else
+ { // TODO: match draw, verifier la getion coté Nest
+ gc.scoreLeft = 0;
+ gc.scoreRight = 0;
+ }
}
await fetch(c.addressBackEnd + "/game/gameserver/updategame",
{
diff --git a/srcs/requirements/game_server/game_back/src/shared_js/enums.ts b/srcs/requirements/game_server/game_back/src/shared_js/enums.ts
index 6d54e139..d6555451 100644
--- a/srcs/requirements/game_server/game_back/src/shared_js/enums.ts
+++ b/srcs/requirements/game_server/game_back/src/shared_js/enums.ts
@@ -31,6 +31,7 @@ export enum InputEnum {
}
export enum PlayerSide {
+ noSide = 0,
left = 1,
right
}
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 89200706..a4ece577 100644
--- a/srcs/requirements/svelte/api_front/src/pages/game/Game.svelte
+++ b/srcs/requirements/svelte/api_front/src/pages/game/Game.svelte
@@ -13,25 +13,20 @@
let allUsers;
//Game's stuff
- let optionsAreNotSet = true;
const options = new pong.InitOptions();
-
- //Game's stuff client side only
const gameAreaId = "game_area";
- //html boolean for pages
- let showWaitPage = false;
- let showInvitations = false;
- let showGameOption = true;
- let showError = false;
+ //boolean for html page
let hiddenGame = true;
- let showMatchEnded = false;
+ let optionsAreNotSet = true;
+ let showGameOptions = true;
+ let showInvitations = false;
+ let showError = false;
+ let errorMessage = "";
+ let showWaitPage = false;
- let isThereAnyInvitation = false;
let invitations = [];
- let waitingMessage = "Please wait...";
- let errorMessageWhenAttemptingToGetATicket = "";
let watchGameStateInterval;
const watchGameStateIntervalRate = 142;
@@ -48,6 +43,17 @@
pong.destroy();
})
+ function resetPage() {
+ hiddenGame = true;
+ optionsAreNotSet = true;
+ showGameOptions = true;
+ showInvitations = false;
+ showError = false;
+ showWaitPage = false;
+ options.reset(user.username);
+ pong.destroy();
+ };
+
const initGame = async() =>
{
optionsAreNotSet = false;
@@ -63,31 +69,29 @@
gameOptions : matchOptions,
isGameIsWithInvitation : options.isSomeoneIsInvited
})
- })
+ });
const responseFromServer = await responseWhenGrantToken;
const responseInjson = await responseFromServer.json();
const token : string = responseInjson.token;
showWaitPage = false;
- console.log("status : " + responseFromServer.status)
+ console.log("status : " + responseFromServer.status);
if (responseFromServer.status != 200)
{
- console.log(responseInjson)
+ console.log(responseInjson);
console.log("On refuse le ticket");
- errorMessageWhenAttemptingToGetATicket = responseInjson.message;
+ errorMessage = responseInjson.message;
showError = true;
- options.reset();
- options.playerOneUsername = user.username;
+ options.reset(user.username);
setTimeout(() => {
- optionsAreNotSet = true
+ optionsAreNotSet = true;
showError = false;
- // showWaitPage = false // ???
+ errorMessage = "";
}, 5000);
}
else if (token)
{
watchGameStateInterval = setInterval(watchGameState, watchGameStateIntervalRate);
- // options.isInvitedPerson = false // ???
- pong.init(options, gameAreaId, token);
+ pong.init(matchOptions, options, gameAreaId, token);
hiddenGame = false;
}
// TODO: Un "else" peut-être ? Si pas de token on fait un truc ?
@@ -96,25 +100,25 @@
const initGameForInvitedPlayer = async(invitation : any) =>
{
- optionsAreNotSet = false
- showWaitPage = true
- console.log("invitation : ")
- console.log(invitation)
+ optionsAreNotSet = false;
+ showWaitPage = true;
+ console.log("invitation : ");
+ console.log(invitation);
if (invitation.token)
{
watchGameStateInterval = setInterval(watchGameState, watchGameStateIntervalRate);
options.playerOneUsername = invitation.playerOneUsername;
options.playerTwoUsername = invitation.playerTwoUsername;
options.isSomeoneIsInvited = true;
- options.isInvitedPerson = true
- pong.init(options, gameAreaId, invitation.token);
- showWaitPage = false
+ options.isInvitedPerson = true;
+ pong.init(invitation.gameOptions, options, gameAreaId, invitation.token);
+ showWaitPage = false;
hiddenGame = false;
}
}
const watchGameState = () => {
- console.log("watchGameState")
+ console.log("watchGameState");
if (gameState) { // trigger Svelte reactivity
gameState.matchStarted = gameState.matchStarted;
gameState.matchEnded = gameState.matchEnded;
@@ -123,34 +127,24 @@
if (gameState.matchAborted || gameState.matchEnded)
{
clearInterval(watchGameStateInterval);
- console.log("watchGameState, end")
- showWaitPage = false
- gameState.matchAborted ?
- errorMessageWhenAttemptingToGetATicket = "The match has been aborted"
- : errorMessageWhenAttemptingToGetATicket = "The match is finished !"
- gameState.matchAborted ? showError = true : showMatchEnded = true;
+ console.log("watchGameState, end");
setTimeout(() => {
resetPage();
- errorMessageWhenAttemptingToGetATicket = "";
- isThereAnyInvitation = false;
- invitations = []; // ???
- console.log("watchGameState : setTimeout")
+ console.log("watchGameState : setTimeout");
}, 5000);
}
}
-
- const showOptions = () => {
- showGameOption = true
- showInvitations = false
+ const switchToGameOptions = () => {
+ showGameOptions = true;
+ showInvitations = false;
}
- const showInvitation = async() => {
- showGameOption = false;
+ const fetchInvitations = async() => {
+ showGameOptions = false;
showInvitations = true;
invitations = await fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/game/invitations`)
- .then(x => x.json())
- invitations.length !== 0 ? isThereAnyInvitation = true : isThereAnyInvitation = false
+ .then(x => x.json());
}
const rejectInvitation = async(invitation) => {
@@ -162,30 +156,23 @@
})
})
.then(x => x.json())
- .catch(error => console.log(error))
- showInvitation()
+ .catch(error => console.log(error));
+ fetchInvitations();
}
- const acceptInvitation = async(invitation : any) => {
- const res = await fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/game/accept`, {
+ const acceptInvitation = async(invitation : any) =>
+ {
+ const res = await fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/game/accept`, {
method: "POST",
headers: { 'Content-Type': 'application/json'},
body: JSON.stringify({
token : invitation.token
})
- })
- .then(x => x.json())
- .catch(error => {
- console.log(error)
- })
- if (res.status === 200)
- {
- showInvitation()
- initGameForInvitedPlayer(invitation)
- }
- //Au final c'est utile !
+ }).catch(error => console.log(error));
- initGameForInvitedPlayer(invitation) // Luke: normal de initGameForInvitedPlayer() sur un "res.status" different de 200 ?
+ if (res && res.ok) {
+ initGameForInvitedPlayer(invitation);
+ }
}
function leaveMatch() {
@@ -193,16 +180,6 @@
resetPage();
};
- function resetPage() {
- hiddenGame = true;
- optionsAreNotSet = true
- showError = false;
- showMatchEnded = false;
- options.reset();
- options.playerOneUsername = user.username;
- pong.destroy();
- };
-
@@ -210,53 +187,61 @@
Might become useless after CSS rework. -->
- {#if showMatchEnded === true}
-
-
{errorMessageWhenAttemptingToGetATicket}
-
- {/if}
- {#if showError === true}
-
+ {#if showError}
+
{/if}
+ {#if !hiddenGame}
+ {#if gameState.matchEnded}
+
+
The match is finished !
+
+ {:else if gameState.matchAborted}
+
+
The match has been aborted
+
+ {/if}
+ {/if}
+
+
{#if !hiddenGame}
- {#if !hiddenGame && gameState.matchStarted && !gameState.matchEnded}
-
-
+ {#if gameState.matchStarted && !gameState.matchEnded}
+
+
- {:else if !hiddenGame && !gameState.matchStarted}
-
-
+ {:else if !gameState.matchStarted}
+
+
{/if}
{/if}
- {#if showWaitPage === true}
-
+ {#if showWaitPage}
+
{/if}
-
+
{#if optionsAreNotSet}
- {#if showGameOption === true}
+ {#if showGameOptions}
-
-
-