From 3564ef6ee24b451f88a80dffa8b3a475c15c42ee Mon Sep 17 00:00:00 2001 From: estellon Date: Tue, 30 Jul 2024 18:52:14 +0200 Subject: [PATCH] ball --- pong/static/game.js | 24 +++++++----- pong/static/index.html | 84 +++++++++++++++++++++--------------------- pong/static/styles.css | 44 +++++++++++++++++----- 3 files changed, 91 insertions(+), 61 deletions(-) diff --git a/pong/static/game.js b/pong/static/game.js index 8c5a1b1..b7d38cb 100644 --- a/pong/static/game.js +++ b/pong/static/game.js @@ -10,6 +10,8 @@ document.addEventListener('DOMContentLoaded', () => { const loginPasswordInput = document.getElementById('login-password'); const loginForm = document.getElementById('login-form'); const registerForm = document.getElementById('register-form'); + const formBlock = document.getElementById('block-form'); + let socket; let token; @@ -17,7 +19,7 @@ document.addEventListener('DOMContentLoaded', () => { // Auto-focus and key handling for AUTH-FORM nicknameInput.focus(); - nicknameInput.addEventListener('keypress', function(event) { + nicknameInput.addEventListener('keypress', function (event) { if (event.key === 'Enter') { event.preventDefault(); checkNicknameButton.click(); @@ -52,15 +54,15 @@ document.addEventListener('DOMContentLoaded', () => { num_won_tournaments: numWonTournaments }) }); - + if (!response.ok) { const errorData = await response.json(); throw new Error(errorData.error || 'Network response was not ok'); } - + const data = await response.json(); return data; - + } catch (error) { // Afficher l'erreur avec un message plus spécifique console.error('Error creating player:', error.message); @@ -118,28 +120,28 @@ document.addEventListener('DOMContentLoaded', () => { loginForm.style.display = 'block'; // Auto-focus and key handling for LOGIN-FORM loginPasswordInput.focus(); - loginPasswordInput.addEventListener('keypress', function(event) { + loginPasswordInput.addEventListener('keypress', function (event) { if (event.key === 'Enter') { event.preventDefault(); loginButton.click(); } - }); + }); } else { authForm.style.display = 'none'; registerForm.style.display = 'block'; // Auto-focus and key handling for REGISTER-FORM passwordInput.focus(); - passwordInput.addEventListener('keypress', function(event) { + passwordInput.addEventListener('keypress', function (event) { if (event.key === 'Enter') { confirmPasswordInput.focus(); - confirmPasswordInput.addEventListener('keypress', function(event) { + confirmPasswordInput.addEventListener('keypress', function (event) { if (event.key === 'Enter') { event.preventDefault(); registerButton.click(); } - }); + }); } - }); + }); } } catch (error) { console.error('Error checking user existence:', error); @@ -173,6 +175,7 @@ document.addEventListener('DOMContentLoaded', () => { //await createPlayer(nickname); registerForm.style.display = 'none'; gameContainer.style.display = 'flex'; + formBlock.style.display = 'none'; startWebSocketConnection(token); } else { alert('Registration failed. Please try again.'); @@ -208,6 +211,7 @@ document.addEventListener('DOMContentLoaded', () => { if (result) { loginForm.style.display = 'none'; gameContainer.style.display = 'flex'; + formBlock.style.display = 'none'; startWebSocketConnection(token); } else { alert('Authentication failed. Please try again.'); diff --git a/pong/static/index.html b/pong/static/index.html index e2ff4ed..63fc79c 100644 --- a/pong/static/index.html +++ b/pong/static/index.html @@ -1,6 +1,7 @@ {% load static %} + @@ -9,42 +10,42 @@ -
-
-
- -
-
-
-
-
+ +
- -
-

BIENVENUE DANS LE PONG 42

-
-
- - - +
+
+
+
- +