diff --git a/app.js b/app.js index e8d3a20fa3c332430134781ac38d8b60614dd65f..d13266e81962ed462405663bc352d80fe19bf961 100644 --- a/app.js +++ b/app.js @@ -26,7 +26,16 @@ app.use(express.static(path.join(__dirname, 'htdocs'))); http.listen(port , ()=>{ console.log("Listening on http://localhost${port}/"); }); + + let rooms = []; + +let gameState = {} + + + + + io.on('connection', (socket) => { console.log(`[connection] ${socket.id}`); @@ -54,7 +63,13 @@ io.on('connection', (socket) => { io.to(socket.id).emit('join room', room.id); if (room.players.length === 2) { + gameState = { + player1: { time: 300, isTurn: false }, // 5 minutes pour chaque joueur + player2: { time: 300, isTurn: false }, + }; io.to(room.id).emit('start game', room.players); + gameState.player1.isTurn = true + room.timer = setInterval(() => updateTimers(gameState, room.id), 1000); } }); @@ -64,6 +79,19 @@ io.on('connection', (socket) => { socket.on('play', (data) => { console.log(`[Server] Play reçu : ${JSON.stringify(data)}`); // Debugging + // Change le tour du joueur + if (gameState.player1.isTurn) { + gameState.player1.isTurn = false; + gameState.player2.isTurn = true; + } else { + gameState.player1.isTurn = true; + gameState.player2.isTurn = false; + } + + // Diffuser l'update des timers et du tour aux clients + io.to(data.roomId).emit('update-timer', gameState); // Diffuser les timers mis à jour + + socket.broadcast.emit('play', data); // On diffuse à tous les clients }); socket.on('roque', (data) => { @@ -114,4 +142,27 @@ function createRoom(player) { function roomId() { return Math.random().toString(36).substr(2, 9); -} \ No newline at end of file +} + +// Fonction qui met à jour les timers toutes les secondes +function updateTimers(gameState) { + // Si c'est le tour du joueur 1, décrémenter son temps + if (gameState.player1.isTurn) { + gameState.player1.time--; + io.emit('update-timer', gameState); // Diffuser l'état des timers aux clients + } + + // Si c'est le tour du joueur 2, décrémenter son temps + if (gameState.player2.isTurn) { + gameState.player2.time--; + io.emit('update-timer', gameState); + } + + // Si un joueur atteint 0 seconde, fin du jeu ou message d'alerte + if (gameState.player1.time <= 0 || gameState.player2.time <= 0) { + io.emit('game-over', 'Temps écoulé !'); + } +} + +// Mettre à jour chaque seconde + diff --git a/htdocs/style.css b/htdocs/style.css index d0219ce2a959e3a5135131ea5aeade716c4e6ee4..f1a0f395ee6d16560c4973cc386f4a23fc0c7fb6 100644 --- a/htdocs/style.css +++ b/htdocs/style.css @@ -1,3 +1,22 @@ .board.black-perspective { transform: rotate(180deg); + transform-origin: center; +} +.btn-primary { + background-color: rgb(243, 8, 149) !important; /* Change la couleur des boutons primaires */ + border-radius: 10px; /* Arrondi les bords */ +} +body { + font-family: 'Libre Baskerville', serif; /* Utilisation de la police de style rétro */ + background-image: url('fond-ecran.jpg') !important; /* Remplace par le nom de ton fichier */ + background-size: cover !important; /* Ajuste l'image pour qu'elle couvre tout l'écran */ + background-position: center !important; /* Centre l'image */ + background-repeat: no-repeat !important; /* Empêche la répétition */ + background-color:rgb(0, 0, 0) +} +#echec-message { + font-family: 'Anton', sans-serif; + font-weight: bold; + font-size: 2rem; /* Taille du texte pour bien le voir */ + color: red; /* Ou une autre couleur qui attire l'attention */ }