ajout de la verification de la porte
This commit is contained in:
@@ -99,8 +99,20 @@
|
||||
player.x = newX;
|
||||
player.y = newY;
|
||||
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>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -14,6 +14,8 @@ let waitingPlayer = null;
|
||||
// Sert tous les fichiers du dossier "client"
|
||||
app.use(express.static(path.join(__dirname, "..", "client")));
|
||||
|
||||
const correctDoor = { x : 3, y : 6};
|
||||
|
||||
io.on("connection", (socket) => {
|
||||
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", () => {
|
||||
console.log("Client deconnecte : ${socket.id}");
|
||||
if (waitingPlayer === socket){
|
||||
|
||||
Reference in New Issue
Block a user