Site
- Add function for request game
This commit is contained in:
@ -6,7 +6,7 @@
|
|||||||
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
|
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/08/07 17:40:15 by edbernar #+# #+# */
|
/* Created: 2024/08/07 17:40:15 by edbernar #+# #+# */
|
||||||
/* Updated: 2024/09/14 23:59:41 by edbernar ### ########.fr */
|
/* Updated: 2024/09/15 10:32:23 by edbernar ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -189,18 +189,18 @@ function connect(e)
|
|||||||
|
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
sendRequest("login", {type: "byPass", mail: mail, password: e.target.password.value});
|
sendRequest("login", {type: "byPass", mail: mail, password: e.target.password.value});
|
||||||
waitForLogin().then((isConnected) => {
|
// waitForLogin().then((isConnected) => {
|
||||||
if (isConnected)
|
// if (isConnected)
|
||||||
{
|
// {
|
||||||
usernameNode = document.createTextNode(userMeInfo.username);
|
// usernameNode = document.createTextNode(userMeInfo.username);
|
||||||
loginButton.replaceChild(usernameNode, pLoginButton);
|
// loginButton.replaceChild(usernameNode, pLoginButton);
|
||||||
CN.new("Connected successfully", "Welcome " + userMeInfo.username, CN.defaultIcon.success);
|
// CN.new("Connected successfully", "Welcome " + userMeInfo.username, CN.defaultIcon.success);
|
||||||
popout.style.display = 'none';
|
// popout.style.display = 'none';
|
||||||
}
|
// }
|
||||||
}).catch((err) => {
|
// }).catch((err) => {
|
||||||
console.error(err);
|
// console.error(err);
|
||||||
CN.new("Error", "An error occured while trying to connect", CN.defaultIcon.error);
|
// CN.new("Error", "An error occured while trying to connect", CN.defaultIcon.error);
|
||||||
});
|
// });
|
||||||
}
|
}
|
||||||
|
|
||||||
export { Login, changeWindowLoginBack };
|
export { Login, changeWindowLoginBack };
|
@ -0,0 +1,26 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* typeGame.js :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2024/09/15 12:00:01 by edbernar #+# #+# */
|
||||||
|
/* Updated: 2024/09/15 12:46:12 by edbernar ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
import { WaitingGamePage } from "/static/javascript/waitingGame/main.js"
|
||||||
|
import { pageRenderer } from '/static/javascript/main.js'
|
||||||
|
|
||||||
|
function typeGame(content)
|
||||||
|
{
|
||||||
|
if (content.action == 1)
|
||||||
|
{
|
||||||
|
if (pageRenderer.actualPage == WaitingGamePage)
|
||||||
|
WaitingGamePage.showOpponent(content.username);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export { typeGame };
|
||||||
|
|
@ -6,14 +6,15 @@
|
|||||||
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
|
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/09/14 21:20:45 by edbernar #+# #+# */
|
/* Created: 2024/09/14 21:20:45 by edbernar #+# #+# */
|
||||||
/* Updated: 2024/09/14 23:24:24 by edbernar ### ########.fr */
|
/* Updated: 2024/09/15 12:57:52 by edbernar ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
import { sendRequest } from "/static/javascript/websocket.js";
|
import { sendRequest } from "/static/javascript/websocket.js";
|
||||||
import { pageRenderer } from '/static/javascript/main.js'
|
import { pageRenderer } from '/static/javascript/main.js'
|
||||||
|
|
||||||
let intervalPoints = null;
|
let intervalPoints = null;
|
||||||
|
let timeout = null;
|
||||||
|
|
||||||
class WaitingGamePage
|
class WaitingGamePage
|
||||||
{
|
{
|
||||||
@ -36,7 +37,9 @@ class WaitingGamePage
|
|||||||
points = '';
|
points = '';
|
||||||
sentence.innerText = text + points;
|
sentence.innerText = text + points;
|
||||||
}, 500);
|
}, 500);
|
||||||
sendRequest("game", {action: 0})
|
timeout = setTimeout(() => {
|
||||||
|
sendRequest("game", {action: 0})
|
||||||
|
}, 1500);
|
||||||
returnButton.addEventListener('click', returnToLobby);
|
returnButton.addEventListener('click', returnToLobby);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,11 +48,29 @@ class WaitingGamePage
|
|||||||
if (intervalPoints)
|
if (intervalPoints)
|
||||||
clearInterval(intervalPoints);
|
clearInterval(intervalPoints);
|
||||||
intervalPoints = null;
|
intervalPoints = null;
|
||||||
|
if (timeout)
|
||||||
|
clearTimeout(timeout);
|
||||||
|
timeout = null;
|
||||||
|
returnButton.removeEventListener('click', returnToLobby);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static showOpponent(username)
|
||||||
|
{
|
||||||
|
const returnButton = document.getElementById('returnToLobbyButton');
|
||||||
|
const sentence = document.getElementById('sentence');
|
||||||
|
|
||||||
|
if (intervalPoints)
|
||||||
|
clearInterval(intervalPoints);
|
||||||
|
intervalPoints = null;
|
||||||
|
sentence.innerText = "Match found";
|
||||||
|
document.body.removeChild(returnButton);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function returnToLobby()
|
function returnToLobby()
|
||||||
{
|
{
|
||||||
|
sendRequest("game", {action: 2});
|
||||||
for (let i = 0; i < document.body.children.length; i++)
|
for (let i = 0; i < document.body.children.length; i++)
|
||||||
{
|
{
|
||||||
document.body.children[i].style.animation = "anim3 0.6s";
|
document.body.children[i].style.animation = "anim3 0.6s";
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
|
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/07/31 22:17:24 by edbernar #+# #+# */
|
/* Created: 2024/07/31 22:17:24 by edbernar #+# #+# */
|
||||||
/* Updated: 2024/09/12 18:18:53 by edbernar ### ########.fr */
|
/* Updated: 2024/09/15 11:55:47 by edbernar ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -20,6 +20,7 @@ import { typeCreateAccount } from "/static/javascript/typeResponse/typeCreateAcc
|
|||||||
import { typeAllListUser }from "/static/javascript/typeResponse/typeAllListUser.js";
|
import { typeAllListUser }from "/static/javascript/typeResponse/typeAllListUser.js";
|
||||||
import { createNotification as CN } from "/static/javascript/notification/main.js";
|
import { createNotification as CN } from "/static/javascript/notification/main.js";
|
||||||
import { typeLogin } from "/static/javascript/typeResponse/typeLogin.js";
|
import { typeLogin } from "/static/javascript/typeResponse/typeLogin.js";
|
||||||
|
import { typeGame } from "/static/javascript/typeResponse/typeGame.js"
|
||||||
|
|
||||||
let socket = null;
|
let socket = null;
|
||||||
let status = 0;
|
let status = 0;
|
||||||
@ -29,8 +30,8 @@ function launchSocket()
|
|||||||
{
|
{
|
||||||
socket = new WebSocket('/ws');
|
socket = new WebSocket('/ws');
|
||||||
|
|
||||||
const typeResponse = ["logged_in", "login", "private_list_user", "private_list_message", "new_private_message", "all_list_user", "create_account"];
|
const typeResponse = ["logged_in", "login", "private_list_user", "private_list_message", "new_private_message", "all_list_user", "create_account", "game"];
|
||||||
const functionResponse = [typeLogin, typeLogin, typePrivateListUser, typePrivateListMessage, typeNewPrivateMessage, typeAllListUser, typeCreateAccount];
|
const functionResponse = [typeLogin, typeLogin, typePrivateListUser, typePrivateListMessage, typeNewPrivateMessage, typeAllListUser, typeCreateAccount, typeGame];
|
||||||
|
|
||||||
const errorCode = [9007, 9010, 9011];
|
const errorCode = [9007, 9010, 9011];
|
||||||
const errorFunction = [typeErrorInvalidPassword, typeErrorInvalidToken42, typeErrorUnknown42Account];
|
const errorFunction = [typeErrorInvalidPassword, typeErrorInvalidToken42, typeErrorUnknown42Account];
|
||||||
|
Reference in New Issue
Block a user