This commit is contained in:
estellon 2024-07-30 18:52:14 +02:00
parent 1495f3ca64
commit 3564ef6ee2
3 changed files with 91 additions and 61 deletions

View File

@ -10,6 +10,8 @@ document.addEventListener('DOMContentLoaded', () => {
const loginPasswordInput = document.getElementById('login-password'); const loginPasswordInput = document.getElementById('login-password');
const loginForm = document.getElementById('login-form'); const loginForm = document.getElementById('login-form');
const registerForm = document.getElementById('register-form'); const registerForm = document.getElementById('register-form');
const formBlock = document.getElementById('block-form');
let socket; let socket;
let token; let token;
@ -17,7 +19,7 @@ document.addEventListener('DOMContentLoaded', () => {
// Auto-focus and key handling for AUTH-FORM // Auto-focus and key handling for AUTH-FORM
nicknameInput.focus(); nicknameInput.focus();
nicknameInput.addEventListener('keypress', function(event) { nicknameInput.addEventListener('keypress', function (event) {
if (event.key === 'Enter') { if (event.key === 'Enter') {
event.preventDefault(); event.preventDefault();
checkNicknameButton.click(); checkNicknameButton.click();
@ -52,15 +54,15 @@ document.addEventListener('DOMContentLoaded', () => {
num_won_tournaments: numWonTournaments num_won_tournaments: numWonTournaments
}) })
}); });
if (!response.ok) { if (!response.ok) {
const errorData = await response.json(); const errorData = await response.json();
throw new Error(errorData.error || 'Network response was not ok'); throw new Error(errorData.error || 'Network response was not ok');
} }
const data = await response.json(); const data = await response.json();
return data; return data;
} catch (error) { } catch (error) {
// Afficher l'erreur avec un message plus spécifique // Afficher l'erreur avec un message plus spécifique
console.error('Error creating player:', error.message); console.error('Error creating player:', error.message);
@ -118,28 +120,28 @@ document.addEventListener('DOMContentLoaded', () => {
loginForm.style.display = 'block'; loginForm.style.display = 'block';
// Auto-focus and key handling for LOGIN-FORM // Auto-focus and key handling for LOGIN-FORM
loginPasswordInput.focus(); loginPasswordInput.focus();
loginPasswordInput.addEventListener('keypress', function(event) { loginPasswordInput.addEventListener('keypress', function (event) {
if (event.key === 'Enter') { if (event.key === 'Enter') {
event.preventDefault(); event.preventDefault();
loginButton.click(); loginButton.click();
} }
}); });
} else { } else {
authForm.style.display = 'none'; authForm.style.display = 'none';
registerForm.style.display = 'block'; registerForm.style.display = 'block';
// Auto-focus and key handling for REGISTER-FORM // Auto-focus and key handling for REGISTER-FORM
passwordInput.focus(); passwordInput.focus();
passwordInput.addEventListener('keypress', function(event) { passwordInput.addEventListener('keypress', function (event) {
if (event.key === 'Enter') { if (event.key === 'Enter') {
confirmPasswordInput.focus(); confirmPasswordInput.focus();
confirmPasswordInput.addEventListener('keypress', function(event) { confirmPasswordInput.addEventListener('keypress', function (event) {
if (event.key === 'Enter') { if (event.key === 'Enter') {
event.preventDefault(); event.preventDefault();
registerButton.click(); registerButton.click();
} }
}); });
} }
}); });
} }
} catch (error) { } catch (error) {
console.error('Error checking user existence:', error); console.error('Error checking user existence:', error);
@ -173,6 +175,7 @@ document.addEventListener('DOMContentLoaded', () => {
//await createPlayer(nickname); //await createPlayer(nickname);
registerForm.style.display = 'none'; registerForm.style.display = 'none';
gameContainer.style.display = 'flex'; gameContainer.style.display = 'flex';
formBlock.style.display = 'none';
startWebSocketConnection(token); startWebSocketConnection(token);
} else { } else {
alert('Registration failed. Please try again.'); alert('Registration failed. Please try again.');
@ -208,6 +211,7 @@ document.addEventListener('DOMContentLoaded', () => {
if (result) { if (result) {
loginForm.style.display = 'none'; loginForm.style.display = 'none';
gameContainer.style.display = 'flex'; gameContainer.style.display = 'flex';
formBlock.style.display = 'none';
startWebSocketConnection(token); startWebSocketConnection(token);
} else { } else {
alert('Authentication failed. Please try again.'); alert('Authentication failed. Please try again.');

View File

@ -1,6 +1,7 @@
{% load static %} {% load static %}
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
@ -9,42 +10,42 @@
<div class="logo"> <div class="logo">
<img src="{% static 'logo-42-perpignan.png' %}" alt="Logo"> <img src="{% static 'logo-42-perpignan.png' %}" alt="Logo">
</div> </div>
<div class="background">
<div class="stars" id="stars"></div>
</div>
</div>
<div class="pong-elements">
<div class="paddle paddle-left"></div>
<div class="paddle paddle-right"></div>
<div class="ball_anim"></div>
</div>
</head> </head>
<body> <body>
<div class="background"> <div class="background">
<div class="stars" id="stars"></div> <div class="stars" id="stars"></div>
</div> </div>
</div> <div class="pong-elements">
<div class="container"> <div class="paddle paddle-left"></div>
<h1>BIENVENUE DANS LE PONG 42</h1> <div class="paddle paddle-right"></div>
<div class="input-container"> <div class="ball_anim"></div>
<div id="auth-form">
<label for="nickname">Enter your nickname:</label>
<input type="text" id="nickname" name="nickname">
<button id="check-nickname">Check Nickname</button>
</div> </div>
<div id="register-form" style="display: none;">
<label for="password">Enter your password:</label> <div class="container" id="block-form">
<input type="password" id="password" name="password"> <h1>BIENVENUE DANS LE PONG 42</h1>
<label for="confirm-password">Confirm your password:</label> <div class="input-container">
<input type="password" id="confirm-password" name="confirm-password"> <div id="auth-form">
<button id="register">Register</button> <label for="nickname">Enter your nickname:</label>
<input type="text" id="nickname" name="nickname">
<button id="check-nickname">Check Nickname</button>
</div>
<div id="register-form" style="display: none;">
<label for="password">Enter your password:</label>
<input type="password" id="password" name="password">
<label for="confirm-password">Confirm your password:</label>
<input type="password" id="confirm-password" name="confirm-password">
<button id="register">Register</button>
</div>
<div id="login-form" style="display: none;">
<label for="login-password">Enter your password:</label>
<input type="password" id="login-password" name="login-password">
<button id="login">Login</button>
</div>
</div>
</div> </div>
<div id="login-form" style="display: none;">
<label for="login-password">Enter your password:</label>
<input type="password" id="login-password" name="login-password">
<button id="login">Login</button>
</div>
</div>
<div id="game1" style="display: none;"> <div id="game1" style="display: none;">
<div id="gameCode" class="game-code">Game Code : </div> <div id="gameCode" class="game-code">Game Code : </div>
<div id="player1-name" class="name">Player 1</div> <div id="player1-name" class="name">Player 1</div>
@ -60,18 +61,19 @@
<script src="{% static 'game.js' %}"></script> <script src="{% static 'game.js' %}"></script>
<script> <script>
const starsContainer = document.getElementById('stars'); const starsContainer = document.getElementById('stars');
for (let i = 0; i < 500; i++) { for (let i = 0; i < 500; i++) {
const star = document.createElement('div'); const star = document.createElement('div');
star.className = 'star'; star.className = 'star';
star.style.width = `${Math.random() * 3}px`; star.style.width = `${Math.random() * 3}px`;
star.style.height = star.style.width; star.style.height = star.style.width;
star.style.left = `${Math.random() * 100}%`; star.style.left = `${Math.random() * 100}%`;
star.style.top = `${Math.random() * 100}%`; star.style.top = `${Math.random() * 100}%`;
star.style.animationDuration = `${Math.random() * 2 + 1}s`; star.style.animationDuration = `${Math.random() * 2 + 1}s`;
starsContainer.appendChild(star); starsContainer.appendChild(star);
} }
setInterval(createTrail, 100); setInterval(createTrail, 100);
</script> </script>
</body> </body>
</html>
</html>

View File

@ -1,5 +1,6 @@
/* General styles */ /* General styles */
body, html { body,
html {
font-family: Arial, sans-serif; font-family: Arial, sans-serif;
color: #00ffff; color: #00ffff;
background-color: #0a0a2a; background-color: #0a0a2a;
@ -25,8 +26,17 @@ input {
} }
button { button {
padding: 10px 20px; background-color: #00ffff;
color: #000033;
border: none;
padding: 1rem 2rem;
font-size: 1.5rem;
cursor: pointer; cursor: pointer;
transition: all 0.3s ease;
border-radius: 10px;
margin-top: 1rem;
text-transform: uppercase;
letter-spacing: 2px;
} }
#game1 { #game1 {
@ -34,6 +44,8 @@ button {
height: 500px; height: 500px;
position: relative; position: relative;
background-color: #000; background-color: #000;
border: 3px solid #00ffff;
box-shadow: 0 0 30px #00ffff, inset 0 0 20px #00ffff;
overflow: hidden; overflow: hidden;
display: flex; display: flex;
justify-content: center; justify-content: center;
@ -57,11 +69,13 @@ button {
} }
#player1-name { #player1-name {
left: 10px; /* Adjust player score position */ left: 10px;
/* Adjust player score position */
} }
#player2-name { #player2-name {
right: 10px; /* Adjust bot score position */ right: 10px;
/* Adjust bot score position */
} }
#game2 { #game2 {
@ -71,7 +85,8 @@ button {
position: absolute; position: absolute;
background-color: #000; background-color: #000;
overflow: hidden; overflow: hidden;
border: 2px solid red; /* Add red border */ border: 2px solid white;
/* Add red border */
display: flex; display: flex;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
@ -84,11 +99,13 @@ button {
} }
#player1-score { #player1-score {
left: 50px; /* Adjust player score position */ left: 50px;
/* Adjust player score position */
} }
#player2-score { #player2-score {
right: 50px; /* Adjust bot score position */ right: 50px;
/* Adjust bot score position */
} }
.pad { .pad {
@ -109,7 +126,7 @@ button {
#ball { #ball {
width: 20px; width: 20px;
height: 20px; height: 20px;
background-color: #ff0000; background-color: #ffffff;
border-radius: 50%; border-radius: 50%;
position: absolute; position: absolute;
} }
@ -190,17 +207,24 @@ button {
} }
@keyframes paddleMove { @keyframes paddleMove {
0% { transform: translateY(10vh); } 0% {
100% { transform: translateY(70vh); } transform: translateY(10vh);
}
100% {
transform: translateY(70vh);
}
} }
@keyframes ballMove { @keyframes ballMove {
0% { 0% {
transform: translateZ(0) scale(1); transform: translateZ(0) scale(1);
} }
50% { 50% {
transform: translateZ(-500px) scale(0.5); transform: translateZ(-500px) scale(0.5);
} }
100% { 100% {
transform: translateZ(0) scale(1); transform: translateZ(0) scale(1);
} }