Site
- update lobbyPage html - starting tournmament Django - add new file with comments for explain
This commit is contained in:
@ -122,6 +122,11 @@
|
||||
<p>CCCCCCCCCC</p>
|
||||
<span class="line"></span>
|
||||
<p>DDDDDDDDDD</p>
|
||||
<br/><br/><br/><br/>
|
||||
<span class="line"></span>
|
||||
<p style="text-align: center;">Tournament code</p>
|
||||
<br/>
|
||||
<input id="tournamentCode" class="search-input" type="text" placeholder="Enter the tournament code (empty for create one)">
|
||||
</div>
|
||||
|
||||
<div class="skin-select">
|
||||
|
@ -0,0 +1,33 @@
|
||||
# **************************************************************************** #
|
||||
# #
|
||||
# ::: :::::::: #
|
||||
# tournamentRequest.py :+: :+: :+: #
|
||||
# +:+ +:+ +:+ #
|
||||
# By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2024/10/01 13:16:39 by edbernar #+# #+# #
|
||||
# Updated: 2024/10/01 14:00:29 by edbernar ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
# tournament request format : {"type":"tournament", "content":{"action": 1, ...}}
|
||||
|
||||
#server actions (actions sent by the server):
|
||||
# 0 : start : tell the client if tournament is full or not exist. If not, tell the client can start the tournament
|
||||
# - exist : true/false
|
||||
# - isFull : true/false
|
||||
# - started : true/false
|
||||
# - code : code of the tournament
|
||||
# 1 : someoneJoin : tell the client someone join the tournament (considering clients will place selon the order of the join)
|
||||
# - id : id of the player
|
||||
# - name : name of the player
|
||||
# - pfp : pfp of the player
|
||||
# 2 : someoneLeave : tell the client someone leave the tournament (if game not started, players will be replaced in the order of the join)
|
||||
# - id : id of the player who leave
|
||||
|
||||
#client actions (actions sent by the client) :
|
||||
# 0 : start : start a tournament. if code == "", create a new tournament, else join the tournament with the code
|
||||
# - code : code of the tournament
|
||||
# 1 : leave : leave the tournament
|
||||
|
||||
|
@ -6,12 +6,13 @@
|
||||
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/25 00:00:21 by edbernar #+# #+# */
|
||||
/* Updated: 2024/09/28 19:48:30 by edbernar ### ########.fr */
|
||||
/* Updated: 2024/10/01 15:12:50 by edbernar ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
import { MultiOnlineGamePage } from "/static/javascript/multiOnlineGame/multiOnlineGamePage.js"
|
||||
import { multiLocalGamePage } from "/static/javascript/multiLocalGame/multiLocalGamePage.js"
|
||||
import { TournamentPage } from "/static/javascript/tournamentPage/TournamentPage.js"
|
||||
import { settingsPage } from "/static/javascript/settingsPage/settingsPage.js"
|
||||
import { WaitingGamePage } from "/static/javascript/waitingGame/main.js"
|
||||
import { ProfilPage } from "/static/javascript/profilPage/main.js";
|
||||
@ -31,6 +32,7 @@ class Page
|
||||
{suffix: false, url:'/wait_game', servUrl: '/waitingGamePage', class: WaitingGamePage, name: 'waitingGamePage', title: 'METH - Wait for a game'},
|
||||
{suffix: true, url:'/profil', servUrl: '/profilPage', class: ProfilPage, name: 'profilPage', title: 'METH - Profil'},
|
||||
{suffix: false, url:'/settings', servUrl: '/settingsPage', class: settingsPage, name: 'settingsPage', title: 'METH - Settings'},
|
||||
// {suffix: true, url:'/tournament', servUrl: '/tournamentPage', class: TournamentPage, name: 'tournamentPage', title: 'METH - Tournament'},
|
||||
]
|
||||
|
||||
constructor()
|
||||
@ -46,6 +48,8 @@ class Page
|
||||
arg = null;
|
||||
if (thisClass.actualPage == MultiOnlineGamePage)
|
||||
sendRequest("game", {action: 2});
|
||||
if (thisClass.actualPage == TournamentPage)
|
||||
sendRequest("tournament", {action: 1});
|
||||
thisClass.changePage(thisClass.availablePages[i].name, true, arg, !thisClass.availablePages[i].suffix);
|
||||
return ;
|
||||
}
|
||||
|
@ -6,11 +6,12 @@
|
||||
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/22 17:08:46 by madegryc #+# #+# */
|
||||
/* Updated: 2024/10/01 01:01:09 by edbernar ### ########.fr */
|
||||
/* Updated: 2024/10/01 15:12:03 by edbernar ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
import { userMeInfo, waitForLogin } from '/static/javascript/typeResponse/typeLogin.js';
|
||||
import { createNotification as CN } from "/static/javascript/notification/main.js";
|
||||
import { barSelecter, goalSelecter } from '/static/javascript/lobbyPage/3d.js';
|
||||
import { LiveChat } from "/static/javascript/liveChat/main.js";
|
||||
import { sendRequest } from "/static/javascript/websocket.js";
|
||||
@ -140,7 +141,7 @@ function startMode()
|
||||
else if (gameMode == 2)
|
||||
startMatchmaking(true);
|
||||
else if (gameMode == 3)
|
||||
alert("Not implemented");
|
||||
startTournmament();
|
||||
}
|
||||
|
||||
function startMultiLocal()
|
||||
@ -163,6 +164,18 @@ function startMatchmaking(ranked)
|
||||
}, 500);
|
||||
}
|
||||
|
||||
function startTournmament()
|
||||
{
|
||||
const code = document.getElementById('tournamentCode').value;
|
||||
|
||||
if (code.length != 6 && code.length != 0)
|
||||
{
|
||||
CN.new("Information", "The code must be 6 characters long or empty");
|
||||
return ;
|
||||
}
|
||||
sendRequest("tournament", {action: 0, code: code});
|
||||
}
|
||||
|
||||
function showGameMode()
|
||||
{
|
||||
document.getElementById('loginPopup').style.display = 'flex';
|
||||
@ -214,7 +227,6 @@ function selectGameModeTwo()
|
||||
goalSelector.dispose();
|
||||
barSelector = null;
|
||||
goalSelector = null;
|
||||
window.gc();
|
||||
barSelector = new barSelecter(document.getElementById('bar'));
|
||||
goalSelector = new goalSelecter(document.getElementById('goal'));
|
||||
gameMode = 1;
|
||||
@ -238,7 +250,6 @@ function selectGameModeThree()
|
||||
goalSelector.dispose();
|
||||
barSelector = null;
|
||||
goalSelector = null;
|
||||
window.gc();
|
||||
barSelector = new barSelecter(document.getElementById('bar1'));
|
||||
goalSelector = new goalSelecter(document.getElementById('goal1'));
|
||||
gameMode = 2;
|
||||
|
@ -0,0 +1,85 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* TournamentPage.js :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/01 13:42:29 by edbernar #+# #+# */
|
||||
/* Updated: 2024/10/01 14:15:12 by edbernar ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
const playerNb = [1, 2, 4, 5, 13, 14, 15, 16];
|
||||
const playerList = {
|
||||
player1: {id: 0, name: null, pfp: null},
|
||||
player2: {id: 0, name: null, pfp: null},
|
||||
player3: {id: 0, name: null, pfp: null},
|
||||
player4: {id: 0, name: null, pfp: null},
|
||||
player13: {id: 0, name: null, pfp: null},
|
||||
player14: {id: 0, name: null, pfp: null},
|
||||
player15: {id: 0, name: null, pfp: null},
|
||||
player16: {id: 0, name: null, pfp: null},
|
||||
};
|
||||
|
||||
class TournamentPage
|
||||
{
|
||||
static create(code)
|
||||
{
|
||||
console.log("Code game : ", code);
|
||||
}
|
||||
|
||||
static dispose()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static newOpponent(content)
|
||||
{
|
||||
let found = false;
|
||||
let i = 0;
|
||||
|
||||
Object.values(playerList).forEach((info) => {
|
||||
if (info.id == 0)
|
||||
found = true;
|
||||
if (!found)
|
||||
i++;
|
||||
});
|
||||
if (!found)
|
||||
{
|
||||
console.warn("Tournament is full.");
|
||||
return ;
|
||||
}
|
||||
console.warn('Put pfp on player' + playerNb[i]);
|
||||
console.warn('Put username on player' + playerNb[i]);
|
||||
playerList['player' + playerNb[i]].id = content.id;
|
||||
playerList['player' + playerNb[i]].pfp = content.pfp;
|
||||
playerList['player' + playerNb[i]].username = content.username;
|
||||
}
|
||||
|
||||
static leaveOpponent(content)
|
||||
{
|
||||
let found = false;
|
||||
let i = 0;
|
||||
|
||||
Object.values(playerList).forEach((info) => {
|
||||
if (info.id == content.id)
|
||||
found = true;
|
||||
if (!found)
|
||||
i++;
|
||||
});
|
||||
if (!found)
|
||||
{
|
||||
console.warn(`Opponent can't be remove cause he is not in this tournament`);
|
||||
return ;
|
||||
}
|
||||
while (i < playerNb.length - 1)
|
||||
{
|
||||
playerList['player' + playerNb[i]] = playerList['player' + playerNb[i + 1]];
|
||||
i++;
|
||||
}
|
||||
playerList['player' + playerNb[i]] = {id: 0, name: null, pfp: null};
|
||||
}
|
||||
}
|
||||
|
||||
export { TournamentPage }
|
@ -0,0 +1,48 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* typeTournament.js :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/01 13:29:50 by edbernar #+# #+# */
|
||||
/* Updated: 2024/10/01 15:13:08 by edbernar ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
import { TournamentPage } from "/static/javascript/tournamentPage/TournamentPage.js"
|
||||
import { createNotification as CN } from "/static/javascript/notification/main.js";
|
||||
import { LobbyPage } from '/static/javascript/lobbyPage/main.js';
|
||||
import { pageRenderer } from '/static/javascript/main.js'
|
||||
|
||||
function typeTournament(content)
|
||||
{
|
||||
if (pageRenderer.actualPage == LobbyPage)
|
||||
{
|
||||
if (content.action == 0)
|
||||
joinTournament(content);
|
||||
}
|
||||
else if (pageRenderer.actualPage == TournamentPage)
|
||||
{
|
||||
if (content.action == 1)
|
||||
TournamentPage.newOpponent(content);
|
||||
if (content.action == 2)
|
||||
TournamentPage.leaveOpponent(content);
|
||||
}
|
||||
else
|
||||
console.warn("Request tournament not for this page...");
|
||||
}
|
||||
|
||||
function joinTournament(content)
|
||||
{
|
||||
if (!content.exist)
|
||||
CN.new("Information", "No game for this code");
|
||||
else if (content.isFull)
|
||||
CN.new("Information", "Cannot join because the game is full");
|
||||
else if (content.started)
|
||||
CN.new("Information", "This tournament has already started");
|
||||
else
|
||||
pageRenderer('tournamentPage', false, content.code);
|
||||
}
|
||||
|
||||
export { typeTournament };
|
@ -6,7 +6,7 @@
|
||||
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/31 22:17:24 by edbernar #+# #+# */
|
||||
/* Updated: 2024/09/28 00:22:40 by edbernar ### ########.fr */
|
||||
/* Updated: 2024/10/01 13:30:48 by edbernar ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -24,6 +24,7 @@ import { typePrivateInfo } from "/static/javascript/typeResponse/typePrivateInfo
|
||||
import { createNotification as CN } from "/static/javascript/notification/main.js";
|
||||
import { typeSearchUser } from "/static/javascript/typeResponse/typeSearchUser.js";
|
||||
import { typeInvitation }from "/static/javascript/typeResponse/typeInvitation.js";
|
||||
import { typeTournament } from "/static/javascript/typeResponse/typeTournament.js";
|
||||
import { typeChangePfp } from "/static/javascript/typeResponse/typeChangePfp.js";
|
||||
import { typeUserInfo } from "/static/javascript/typeResponse/typeUserInfo.js";
|
||||
import { typeLogin } from "/static/javascript/typeResponse/typeLogin.js";
|
||||
@ -39,8 +40,8 @@ function launchSocket()
|
||||
|
||||
socket = new WebSocket('/ws');
|
||||
|
||||
const typeResponse = ["logged_in", "login", "private_list_user", "private_list_message", "new_private_message", "all_list_user", "create_account", "game", "search_user", "user_info", "change_pfp", "private_info", "change_private_info", "invitation"];
|
||||
const functionResponse = [typeLogin, typeLogin, typePrivateListUser, typePrivateListMessage, typeNewPrivateMessage, typeAllListUser, typeCreateAccount, typeGame, typeSearchUser, typeUserInfo, typeChangePfp, typePrivateInfo, typeChangePrivateInfo, typeInvitation];
|
||||
const typeResponse = ["logged_in", "login", "private_list_user", "private_list_message", "new_private_message", "all_list_user", "create_account", "game", "search_user", "user_info", "change_pfp", "private_info", "change_private_info", "invitation", "tournament"];
|
||||
const functionResponse = [typeLogin, typeLogin, typePrivateListUser, typePrivateListMessage, typeNewPrivateMessage, typeAllListUser, typeCreateAccount, typeGame, typeSearchUser, typeUserInfo, typeChangePfp, typePrivateInfo, typeChangePrivateInfo, typeInvitation, typeTournament];
|
||||
|
||||
const errorCode = [9007, 9010, 9011, 9013];
|
||||
const errorFunction = [typeErrorInvalidPassword, typeErrorInvalidToken42, typeErrorUnknown42Account, typeErrorConnectedElsewhere];
|
||||
|
@ -222,6 +222,7 @@ body {
|
||||
flex-direction: column;
|
||||
margin-block: 25px;
|
||||
max-width: 500px;
|
||||
width: 400px;
|
||||
font-size: 1.5rem;
|
||||
}
|
||||
|
||||
@ -449,4 +450,9 @@ body {
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
#tournamentCode {
|
||||
width: 94%;
|
||||
font-size: 0.8rem;
|
||||
}
|
Reference in New Issue
Block a user