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();
@ -118,7 +120,7 @@ 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();
@ -129,10 +131,10 @@ document.addEventListener('DOMContentLoaded', () => {
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();
@ -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,22 +10,20 @@
<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>
<div class="paddle paddle-right"></div>
<div class="ball_anim"></div>
</div>
<div class="container" id="block-form">
<h1>BIENVENUE DANS LE PONG 42</h1> <h1>BIENVENUE DANS LE PONG 42</h1>
<div class="input-container"> <div class="input-container">
<div id="auth-form"> <div id="auth-form">
@ -44,7 +43,9 @@
<input type="password" id="login-password" name="login-password"> <input type="password" id="login-password" name="login-password">
<button id="login">Login</button> <button id="login">Login</button>
</div> </div>
</div> </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>
@ -71,7 +72,8 @@
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);
} }