Site
- request 5-6 ok for tournament
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/01 13:42:29 by edbernar #+# #+# */
|
||||
/* Updated: 2024/10/16 01:10:29 by edbernar ### ########.fr */
|
||||
/* Updated: 2024/10/20 17:58:40 by edbernar ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -139,6 +139,8 @@ class TournamentPage
|
||||
this.newMessage(content.messages[i]);
|
||||
for (let i = 0; i < content.players.length; i++)
|
||||
this.newOpponent(content.players[i]);
|
||||
for (let i = 0; i < content.history.length; i++)
|
||||
this.newEndGame(content.history[i]);
|
||||
}
|
||||
|
||||
static startGame(content)
|
||||
@ -147,6 +149,35 @@ class TournamentPage
|
||||
console.log(content);
|
||||
pageRenderer.changePage("waitingGamePage", false, {username: content.username, id: content.id, isTournament: true, content: content});
|
||||
}
|
||||
|
||||
static newEndGame(content)
|
||||
{
|
||||
const player1Nb = playerNb[content.p1];
|
||||
const player2Nb = playerNb[content.p2];
|
||||
const winner = content.p1Win ? playerList['player' + player1Nb].username : playerList['player' + player2Nb].username;
|
||||
const winnerData = content.p1Win ? playerList['player' + player1Nb] : playerList['player' + player2Nb];
|
||||
let pos = 0;
|
||||
let loserPos = 0;
|
||||
|
||||
newInfo(`${playerList['player' + player1Nb].username} vs ${playerList['player' + player2Nb].username} : <span style="font-weight: bold;">${winner}</span> won.`);
|
||||
if (Math.floor(content.p1 / 2) == Math.floor(content.p2 / 2))
|
||||
{
|
||||
loserPos = content.p1Win ? player2Nb : player1Nb;
|
||||
document.getElementById('pfp-' + loserPos).style.backgroundImage = `linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)), url('${playerList['player' + (content.p1Win ? player2Nb : player1Nb)].pfp}')`;
|
||||
document.getElementById('pfp-' + (player1Nb + player2Nb)).style.backgroundImage = `url(${winnerData.pfp})`;
|
||||
}
|
||||
else
|
||||
{
|
||||
pos = (player1Nb + (player1Nb % 2 == 0 ? player1Nb - 1 : player1Nb)) + (player2Nb + (player2Nb % 2 == 0 ? player2Nb - 1: player2Nb));
|
||||
if (content.p1Win)
|
||||
loserPos = player2Nb + (player2Nb % 2 == 0 ? player2Nb - 1 : player2Nb);
|
||||
else
|
||||
loserPos = player1Nb + (player1Nb % 2 == 0 ? player1Nb - 1 : player1Nb);
|
||||
document.getElementById('pfp-' + pos).style.backgroundImage = `url(${winnerData.pfp})`;
|
||||
console.log("loserPos : ", loserPos);
|
||||
document.getElementById('pfp-' + loserPos).style.backgroundImage = `linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)), url('${playerList['player' + (content.p1Win ? player2Nb : player1Nb)].pfp}')`;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function newInfo(message)
|
||||
@ -184,4 +215,4 @@ function initTournamentChat()
|
||||
});
|
||||
}
|
||||
|
||||
export { TournamentPage }
|
||||
export { TournamentPage };
|
@ -6,7 +6,7 @@
|
||||
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/01 13:29:50 by edbernar #+# #+# */
|
||||
/* Updated: 2024/10/16 01:20:33 by edbernar ### ########.fr */
|
||||
/* Updated: 2024/10/20 18:07:15 by edbernar ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -41,6 +41,8 @@ function typeTournament(content)
|
||||
TournamentPage.startGame(content);
|
||||
else if (content.action == 5)
|
||||
TournamentPage.fetchAllData(content);
|
||||
else if (content.action == 6)
|
||||
TournamentPage.newEndGame(content);
|
||||
}
|
||||
else
|
||||
console.warn("Request tournament not for this page...");
|
||||
@ -64,4 +66,88 @@ function joinTournament(content)
|
||||
}
|
||||
}
|
||||
|
||||
export { typeTournament };
|
||||
export { typeTournament };
|
||||
|
||||
|
||||
|
||||
document.addEventListener('keydown', (event) => {
|
||||
if (event.key === "a")
|
||||
{
|
||||
|
||||
typeTournament(
|
||||
{
|
||||
"action": 5,
|
||||
"players": [
|
||||
// {
|
||||
// "id": 0,
|
||||
// "username": "edbernar",
|
||||
// "pfp": "/static/img/default_pfp.jpg"
|
||||
// },
|
||||
{
|
||||
"id": 1,
|
||||
"username": "bot",
|
||||
"pfp": "/static/img/robot_pfp.jpg"
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"username": "bot",
|
||||
"pfp": "/static/img/robot_pfp.jpg"
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"username": "bot",
|
||||
"pfp": "/static/img/robot_pfp.jpg"
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"username": "bot",
|
||||
"pfp": "/static/img/robot_pfp.jpg"
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"username": "bot",
|
||||
"pfp": "/static/img/robot_pfp.jpg"
|
||||
},
|
||||
{
|
||||
"id": 6,
|
||||
"username": "bot",
|
||||
"pfp": "/static/img/robot_pfp.jpg"
|
||||
},
|
||||
{
|
||||
"id": 7,
|
||||
"username": "bot",
|
||||
"pfp": "/static/img/robot_pfp.jpg"
|
||||
}
|
||||
],
|
||||
"messages": [],
|
||||
"history": [
|
||||
{
|
||||
"p1": 3,
|
||||
"p2": 2,
|
||||
"p1Win": true
|
||||
},
|
||||
{
|
||||
"p1": 5,
|
||||
"p2": 4,
|
||||
"p1Win": true
|
||||
},
|
||||
{
|
||||
"p1": 7,
|
||||
"p2": 6,
|
||||
"p1Win": true
|
||||
},
|
||||
{
|
||||
"p1": 7,
|
||||
"p2": 5,
|
||||
"p1Win": true
|
||||
},
|
||||
{
|
||||
"p1": 1,
|
||||
"p2": 0,
|
||||
"p1Win": false
|
||||
}
|
||||
]
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
|
Reference in New Issue
Block a user