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
ef698fd7
Commit
ef698fd7
authored
1 month ago
by
De Brettes Thomas
Browse files
Options
Downloads
Patches
Plain Diff
Timer
parent
1baad40a
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
app.js
+52
-1
52 additions, 1 deletion
app.js
htdocs/style.css
+19
-0
19 additions, 0 deletions
htdocs/style.css
with
71 additions
and
1 deletion
app.js
+
52
−
1
View file @
ef698fd7
...
...
@@ -26,7 +26,16 @@ app.use(express.static(path.join(__dirname, 'htdocs')));
http
.
listen
(
port
,
()
=>
{
console
.
log
(
"
Listening on http://localhost${port}/
"
);
});
let
rooms
=
[];
let
gameState
=
{}
io
.
on
(
'
connection
'
,
(
socket
)
=>
{
console
.
log
(
`[connection]
${
socket
.
id
}
`
);
...
...
@@ -54,7 +63,13 @@ io.on('connection', (socket) => {
io
.
to
(
socket
.
id
).
emit
(
'
join room
'
,
room
.
id
);
if
(
room
.
players
.
length
===
2
)
{
gameState
=
{
player1
:
{
time
:
300
,
isTurn
:
false
},
// 5 minutes pour chaque joueur
player2
:
{
time
:
300
,
isTurn
:
false
},
};
io
.
to
(
room
.
id
).
emit
(
'
start game
'
,
room
.
players
);
gameState
.
player1
.
isTurn
=
true
room
.
timer
=
setInterval
(()
=>
updateTimers
(
gameState
,
room
.
id
),
1000
);
}
});
...
...
@@ -64,6 +79,19 @@ io.on('connection', (socket) => {
socket
.
on
(
'
play
'
,
(
data
)
=>
{
console
.
log
(
`[Server] Play reçu :
${
JSON
.
stringify
(
data
)}
`
);
// Debugging
// Change le tour du joueur
if
(
gameState
.
player1
.
isTurn
)
{
gameState
.
player1
.
isTurn
=
false
;
gameState
.
player2
.
isTurn
=
true
;
}
else
{
gameState
.
player1
.
isTurn
=
true
;
gameState
.
player2
.
isTurn
=
false
;
}
// Diffuser l'update des timers et du tour aux clients
io
.
to
(
data
.
roomId
).
emit
(
'
update-timer
'
,
gameState
);
// Diffuser les timers mis à jour
socket
.
broadcast
.
emit
(
'
play
'
,
data
);
// On diffuse à tous les clients
});
socket
.
on
(
'
roque
'
,
(
data
)
=>
{
...
...
@@ -115,3 +143,26 @@ function createRoom(player) {
function
roomId
()
{
return
Math
.
random
().
toString
(
36
).
substr
(
2
,
9
);
}
// Fonction qui met à jour les timers toutes les secondes
function
updateTimers
(
gameState
)
{
// Si c'est le tour du joueur 1, décrémenter son temps
if
(
gameState
.
player1
.
isTurn
)
{
gameState
.
player1
.
time
--
;
io
.
emit
(
'
update-timer
'
,
gameState
);
// Diffuser l'état des timers aux clients
}
// Si c'est le tour du joueur 2, décrémenter son temps
if
(
gameState
.
player2
.
isTurn
)
{
gameState
.
player2
.
time
--
;
io
.
emit
(
'
update-timer
'
,
gameState
);
}
// Si un joueur atteint 0 seconde, fin du jeu ou message d'alerte
if
(
gameState
.
player1
.
time
<=
0
||
gameState
.
player2
.
time
<=
0
)
{
io
.
emit
(
'
game-over
'
,
'
Temps écoulé !
'
);
}
}
// Mettre à jour chaque seconde
This diff is collapsed.
Click to expand it.
htdocs/style.css
+
19
−
0
View file @
ef698fd7
.board.black-perspective
{
transform
:
rotate
(
180deg
);
transform-origin
:
center
;
}
.btn-primary
{
background-color
:
rgb
(
243
,
8
,
149
)
!important
;
/* Change la couleur des boutons primaires */
border-radius
:
10px
;
/* Arrondi les bords */
}
body
{
font-family
:
'Libre Baskerville'
,
serif
;
/* Utilisation de la police de style rétro */
background-image
:
url('fond-ecran.jpg')
!important
;
/* Remplace par le nom de ton fichier */
background-size
:
cover
!important
;
/* Ajuste l'image pour qu'elle couvre tout l'écran */
background-position
:
center
!important
;
/* Centre l'image */
background-repeat
:
no-repeat
!important
;
/* Empêche la répétition */
background-color
:
rgb
(
0
,
0
,
0
)
}
#echec-message
{
font-family
:
'Anton'
,
sans-serif
;
font-weight
:
bold
;
font-size
:
2rem
;
/* Taille du texte pour bien le voir */
color
:
red
;
/* Ou une autre couleur qui attire l'attention */
}
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