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
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Elarouti Adam
Echecs
Commits
9bc79dc9
Commit
9bc79dc9
authored
2 months ago
by
De Brettes Thomas
Browse files
Options
Downloads
Patches
Plain Diff
échiquier inversé
parent
fdb40dd0
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
htdocs/index.js
+24
-5
24 additions, 5 deletions
htdocs/index.js
htdocs/page_acceuil2.html
+1
-1
1 addition, 1 deletion
htdocs/page_acceuil2.html
htdocs/style.css
+3
-0
3 additions, 0 deletions
htdocs/style.css
with
28 additions
and
6 deletions
htdocs/index.js
+
24
−
5
View file @
9bc79dc9
...
@@ -108,8 +108,13 @@ socket.on('join room', (roomId) => {
...
@@ -108,8 +108,13 @@ socket.on('join room', (roomId) => {
socket
.
on
(
'
start game
'
,
(
players
)
=>
{
socket
.
on
(
'
start game
'
,
(
players
)
=>
{
console
.
log
(
players
,
"
Le jeu commence
"
);
console
.
log
(
players
,
"
Le jeu commence
"
);
startGame
(
players
);
startGame
(
players
);
console
.
log
(
player
.
isBlackPlayer
)
console
.
log
(
player
.
isBlackPlayer
)
if
(
player
.
isBlackPlayer
)
{
document
.
getElementById
(
'
chessboard
'
).
classList
.
add
(
'
black-perspective
'
);
console
.
log
(
"
échiquier inversé
"
)
}
});
});
...
@@ -174,7 +179,6 @@ function startGame(players) {
...
@@ -174,7 +179,6 @@ function startGame(players) {
turnMsg
.
classList
.
remove
(
'
d-none
'
);
turnMsg
.
classList
.
remove
(
'
d-none
'
);
const
ennemyPlayer
=
players
.
find
(
p
=>
p
.
socketId
!=
player
.
socketId
);
const
ennemyPlayer
=
players
.
find
(
p
=>
p
.
socketId
!=
player
.
socketId
);
draw
();
draw
();
ennemyUsername
=
ennemyPlayer
.
username
;
ennemyUsername
=
ennemyPlayer
.
username
;
tour
=
{
currentPlayer
:
player
,
ennemyPlayer
:
ennemyPlayer
};
tour
=
{
currentPlayer
:
player
,
ennemyPlayer
:
ennemyPlayer
};
...
@@ -250,6 +254,19 @@ function drawPieces() {
...
@@ -250,6 +254,19 @@ function drawPieces() {
if
(
piece
!==
""
)
{
if
(
piece
!==
""
)
{
let
img
=
new
Image
();
let
img
=
new
Image
();
img
.
src
=
"
chess_pieces/
"
+
pieceImages
[
piece
];
img
.
src
=
"
chess_pieces/
"
+
pieceImages
[
piece
];
if
(
player
.
isBlackPlayer
){
img
.
onload
=
function
()
{
ctx
.
save
();
ctx
.
translate
((
col
)
*
size
,
(
row
)
*
size
);
ctx
.
rotate
(
Math
.
PI
);
ctx
.
drawImage
(
img
,
-
size
,
-
size
,
size
,
size
);
ctx
.
restore
();
};
img
.
onerror
=
function
(
e
)
{
console
.
log
(
"
Erreur de chargement de l'image :
"
,
img
.
src
);
// En cas d'erreur de chargement
};
}
else
{
img
.
onload
=
function
()
{
img
.
onload
=
function
()
{
ctx
.
drawImage
(
img
,
col
*
size
,
row
*
size
,
size
,
size
);
ctx
.
drawImage
(
img
,
col
*
size
,
row
*
size
,
size
,
size
);
};
};
...
@@ -260,6 +277,7 @@ function drawPieces() {
...
@@ -260,6 +277,7 @@ function drawPieces() {
}
}
}
}
}
}
}
// Fonction principale pour dessiner l'échiquier
// Fonction principale pour dessiner l'échiquier
function
draw
()
{
function
draw
()
{
...
@@ -611,6 +629,7 @@ function movePiece(piece, newRow, newCol) {
...
@@ -611,6 +629,7 @@ function movePiece(piece, newRow, newCol) {
// Vérifier si le mouvement est valide
// Vérifier si le mouvement est valide
const
validMoves
=
highlightMoves
(
tour
,
piece
,
selectedPosition
.
row
,
selectedPosition
.
col
);
const
validMoves
=
highlightMoves
(
tour
,
piece
,
selectedPosition
.
row
,
selectedPosition
.
col
);
console
.
log
(
validMoves
)
// Vérifier que validMoves est un tableau et qu'il contient des objets avec { row, col }
// Vérifier que validMoves est un tableau et qu'il contient des objets avec { row, col }
const
isValidMove
=
Array
.
isArray
(
validMoves
)
&&
validMoves
.
some
(
m
=>
m
.
row
===
newRow
&&
m
.
col
===
newCol
);
const
isValidMove
=
Array
.
isArray
(
validMoves
)
&&
validMoves
.
some
(
m
=>
m
.
row
===
newRow
&&
m
.
col
===
newCol
);
...
...
This diff is collapsed.
Click to expand it.
htdocs/page_acceuil2.html
+
1
−
1
View file @
9bc79dc9
...
@@ -88,7 +88,7 @@
...
@@ -88,7 +88,7 @@
</div>
</div>
</div>
</div>
</div>
</div>
<canvas
id=
"chessboard"
width=
"480"
height=
"480"
></canvas>
<canvas
id=
"chessboard"
class=
"board"
width=
"480"
height=
"480"
></canvas>
<script
src=
"./jquery/jquery.min.js"
></script>
<script
src=
"./jquery/jquery.min.js"
></script>
<script
src=
"./bootstrap/js/bootstrap.min.js"
></script>
<script
src=
"./bootstrap/js/bootstrap.min.js"
></script>
<script
src=
"/socket.io/socket.io.js"
></script>
<script
src=
"/socket.io/socket.io.js"
></script>
...
...
This diff is collapsed.
Click to expand it.
htdocs/style.css
+
3
−
0
View file @
9bc79dc9
.board.black-perspective
{
transform
:
rotate
(
180deg
);
}
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