- can send message in tournament
    - request 3 server tournamment
Game
    - change buttons position on multi online
This commit is contained in:
Kum1ta
2024-10-05 04:30:20 +02:00
parent 64346413c3
commit d8284b78e2
6 changed files with 52 additions and 16 deletions

View File

@ -3,10 +3,10 @@
# ::: :::::::: #
# Tournament.py :+: :+: :+: #
# +:+ +:+ +:+ #
# By: tomoron <tomoron@student.42.fr> +#+ +:+ +#+ #
# By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2024/10/04 17:17:07 by tomoron #+# #+# #
# Updated: 2024/10/05 03:30:00 by tomoron ### ########.fr #
# Updated: 2024/10/05 03:33:17 by edbernar ### ########.fr #
# #
# **************************************************************************** #
@ -55,7 +55,7 @@ class Tournament:
self.messages.append({"username":socket.username, "message":message})
if(len(self.messages) > 20):
self.messages.pop(0)
self.broadcast({"action":3, "username":socket.username, "message":socket.message})
self.broadcast({"action":3, "username":socket.username, "message":message})
def leave(self, socket):
if(socket not in self.players):

View File

@ -193,7 +193,7 @@
</div>
<span class="line"></span>
<p style="text-align: center; margin-bottom: 20px;">Tournament code</p>
<input id="tournamentCode" class="search-input" type="text" placeholder="Enter the tournament code (empty for create one)">
<input id="tournamentCode" class="search-input" type="text" placeholder="Enter the tournament code (empty to create one)">
</div>
<div class="skin-select">

View File

@ -6,7 +6,7 @@
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/18 00:30:31 by edbernar #+# #+# */
/* Updated: 2024/10/05 01:06:19 by edbernar ### ########.fr */
/* Updated: 2024/10/05 02:41:30 by edbernar ### ########.fr */
/* */
/* ************************************************************************** */
@ -539,7 +539,6 @@ function showGamePad()
gamePad.style.display = 'flex';
document.addEventListener('touchstart', (event) => {
const key = event.target.getAttribute("id");
for (let i = 0; i < keyList.length; i++)
{

View File

@ -6,7 +6,7 @@
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/01 13:42:29 by edbernar #+# #+# */
/* Updated: 2024/10/03 02:27:58 by edbernar ### ########.fr */
/* Updated: 2024/10/05 03:48:19 by edbernar ### ########.fr */
/* */
/* ************************************************************************** */
@ -38,7 +38,9 @@ class TournamentPage
divInfo = document.getElementsByClassName('infoo')[0];
divChat = document.getElementsByClassName('chat')[0];
document.getElementById('code-tournament').innerText = "Code : " + code;
sendRequest("tournament", {action: 3});
divTopInfo.innerText = 'Tournament';
initTournamentChat();
}
static dispose()
@ -103,7 +105,6 @@ class TournamentPage
while (i < playerNb.length - 1)
{
playerList['player' + playerNb[i]] = playerList['player' + playerNb[i + 1]];
console.log(playerList['player' + playerNb[i]]);
document.getElementById('user-' + playerNb[i]).innerText = playerList['player' + playerNb[i]].username;
document.getElementById('pfp-' + playerNb[i]).style.backgroundImage = `url(${playerList['player' + playerNb[i]].pfp})`;
i++;
@ -121,6 +122,14 @@ class TournamentPage
divChat.appendChild(newText);
}
static fetchAllData(content)
{
for (let i = 0; i < content.messages.length; i++)
this.newMessage(content.messages[i]);
for (let i = 0; i < content.players.length; i++)
this.newOpponent(content.players[i]);
}
static startGame(content)
{
pageRenderer.changePage("waitingGamePage", false, {username: content.username, id: content.id, isTournament: true})
@ -136,4 +145,30 @@ function newInfo(message)
divInfo.appendChild(newDiv);
}
function initTournamentChat()
{
const inputMessage = document.getElementById('inputMessage');
const sendButton = document.getElementById("sendButton");
sendButton.style.cursor = "pointer";
sendButton.addEventListener("click", () => {
sendRequest("tournament", {action: 2, message: inputMessage.value});
inputMessage.value = "";
inputMessage.focus();
});
inputMessage.addEventListener("keyup", (event) => {
if (event.key === "Enter" && inputMessage.value.trim() !== "")
{
event.preventDefault();
sendRequest("tournament", {action: 2, message: inputMessage.value});
inputMessage.value = "";
inputMessage.focus();
}
});
inputMessage.addEventListener("keydown", (event) => {
if (event.key === "Enter")
event.preventDefault();
});
}
export { TournamentPage }

View File

@ -6,7 +6,7 @@
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/01 13:29:50 by edbernar #+# #+# */
/* Updated: 2024/10/03 01:17:26 by edbernar ### ########.fr */
/* Updated: 2024/10/05 03:02:38 by edbernar ### ########.fr */
/* */
/* ************************************************************************** */
@ -38,6 +38,8 @@ function typeTournament(content)
TournamentPage.newMessage(content);
else if (content.action == 4)
TournamentPage.startGame(content);
else if (content.action == 5)
TournamentPage.fetchAllData(content);
}
else
console.warn("Request tournament not for this page...");

View File

@ -6,7 +6,7 @@
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/20 11:23:41 by edbernar #+# #+# */
/* Updated: 2024/10/04 17:35:50 by edbernar ### ########.fr */
/* Updated: 2024/10/05 02:14:49 by edbernar ### ########.fr */
/* */
/* ************************************************************************** */
@ -122,8 +122,8 @@ body {
.gamePad .gamePadLeft {
display: flex;
position: absolute;
left: 50px;
bottom: 50px;
left: 30px;
bottom: 30px;
user-select: none;
-webkit-user-select: none;
-ms-user-select: none;
@ -135,8 +135,8 @@ body {
display: flex;
position: absolute;
flex-direction: column;
right: 50px;
bottom: 50px;
right: 30px;
bottom: 30px;
user-select: none;
-webkit-user-select: none;
-ms-user-select: none;
@ -159,7 +159,7 @@ body {
}
.gamePadLeft #padRight {
margin-left: 50px;
margin-left: 10px;
transform: rotate(180deg);
user-select: none;
-webkit-user-select: none;
@ -168,7 +168,7 @@ body {
}
.gamePadRight #padTop {
margin-bottom: 20px;
margin-bottom: 10px;
transform: rotate(90deg);
user-select: none;
-webkit-user-select: none;