Skip to content
Snippets Groups Projects
Commit a4a918a4 authored by Elarouti Adam's avatar Elarouti Adam
Browse files

Mouvement piece

parent 322892f5
No related merge requests found
...@@ -71,3 +71,51 @@ function draw() { ...@@ -71,3 +71,51 @@ function draw() {
// Appeler la fonction pour afficher l'échiquier // Appeler la fonction pour afficher l'échiquier
draw(); draw();
//Mouvement des pièces sur l'échiquier
let selectedPiece = null;
let selectedPosition = null;
canvas.addEventListener("click", function(event) {
console.log("clické")
const col = Math.floor(event.offsetX / size);
const row = Math.floor(event.offsetY / size);
if (selectedPiece) {
movePiece(row, col);
} else {
selectPiece(row, col);
}
});
function selectPiece(row, col) {
const piece = board[row][col];
if (piece !== "") { // Vérifier que ce n'est pas une case vide
selectedPiece = piece;
selectedPosition = { row, col };
}
}
function movePiece(newRow, newCol) {
if (!selectedPiece) return;
// Vérifier si le mouvement est valide
//const validMoves = highlightMoves(selectedPiece, selectedPosition.row, selectedPosition.col);
//const isValidMove = validMoves.some(m => m.row === newRow && m.col === newCol);
//if (isValidMove) {
board[newRow][newCol] = selectedPiece;
board[selectedPosition.row][selectedPosition.col] = "";
selectedPiece = null;
selectedPosition = null;
drawBoard();
drawPieces();
//}
}
\ No newline at end of file
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<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">
<title>AdamLeMaitre</title> <title>Thomas le Braîtte</title>
<link rel="stylesheet" href="style_page_jeu.css"> <link rel="stylesheet" href="style_page_jeu.css">
</head> </head>
<body> <body>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment