Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
Echecs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Elarouti Adam
Echecs
Commits
a4a918a4
Commit
a4a918a4
authored
3 months ago
by
Elarouti Adam
Browse files
Options
Downloads
Patches
Plain Diff
Mouvement piece
parent
322892f5
Loading
Loading
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
htdocs/chess.js
+48
-0
48 additions, 0 deletions
htdocs/chess.js
htdocs/page_jeu.html
+1
-1
1 addition, 1 deletion
htdocs/page_jeu.html
with
49 additions
and
1 deletion
htdocs/chess.js
+
48
−
0
View file @
a4a918a4
...
@@ -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
This diff is collapsed.
Click to expand it.
htdocs/page_jeu.html
+
1
−
1
View file @
a4a918a4
...
@@ -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>
AdamLeMaitr
e
</title>
<title>
Thomas le Braîtt
e
</title>
<link
rel=
"stylesheet"
href=
"style_page_jeu.css"
>
<link
rel=
"stylesheet"
href=
"style_page_jeu.css"
>
</head>
</head>
<body>
<body>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment