ajout de la verification de la porte

This commit is contained in:
2026-07-31 03:02:21 +02:00
parent 914dbe2368
commit 81e2623e2a
2 changed files with 26 additions and 0 deletions

View File

@@ -99,8 +99,20 @@
player.x = newX; player.x = newX;
player.y = newY; player.y = newY;
render(); render();
if (maze[newY][newX] === 2){
socket.emit("door_reached", { x: newX, y: newY});
}
} }
}); });
socket.on("door_result", (result) => {
if (result.correct){
console.log("Bonne porte ! Victoire (pour cette manche).");
} else {
console.log("Mauvaise porte. Partie terminee.");
}
})
</script> </script>
</body> </body>
</html> </html>

View File

@@ -14,6 +14,8 @@ let waitingPlayer = null;
// Sert tous les fichiers du dossier "client" // Sert tous les fichiers du dossier "client"
app.use(express.static(path.join(__dirname, "..", "client"))); app.use(express.static(path.join(__dirname, "..", "client")));
const correctDoor = { x : 3, y : 6};
io.on("connection", (socket) => { io.on("connection", (socket) => {
console.log("Un client s'est connecte : ${socket.id}"); console.log("Un client s'est connecte : ${socket.id}");
@@ -42,6 +44,18 @@ io.on("connection", (socket) => {
} }
}); });
socket.on("door_reached", (position) => {
const partnerId = socket.data.partnerId;
const isCorrect = position.x === correctDoor.x && position.y === correctDoor.y;
const result = {correct: isCorrect};
socket.emit("door_result", result);
if (partnerId){
io.to(partnerId).emit("door_result", result);
}
});
socket.on("disconnect", () => { socket.on("disconnect", () => {
console.log("Client deconnecte : ${socket.id}"); console.log("Client deconnecte : ${socket.id}");
if (waitingPlayer === socket){ if (waitingPlayer === socket){