Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Connect4
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
Durand Ulysse
Connect4
Commits
022a9a2d
Commit
022a9a2d
authored
2 months ago
by
Ulysse Durand
Browse files
Options
Downloads
Patches
Plain Diff
fonctionne
parent
7f44d047
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
public/index.html
+1
-0
1 addition, 0 deletions
public/index.html
public/room.html
+6
-2
6 additions, 2 deletions
public/room.html
server.js
+6
-2
6 additions, 2 deletions
server.js
test
+0
-0
0 additions, 0 deletions
test
with
13 additions
and
4 deletions
public/index.html
+
1
−
0
View file @
022a9a2d
...
...
@@ -65,6 +65,7 @@
function
joinRoom
(
roomNum
)
{
const
name
=
nameInput
.
value
.
trim
();
if
(
document
.
querySelectorAll
(
'
.player-count
'
)[
roomNum
].
textContent
==
"
2
"
)
return
alert
(
'
Full room
'
);
if
(
!
name
)
return
alert
(
'
Please enter a name
'
);
window
.
location
.
href
=
`/room
${
roomNum
}
?name=
${
encodeURIComponent
(
name
)}
`
;
}
...
...
This diff is collapsed.
Click to expand it.
public/room.html
+
6
−
2
View file @
022a9a2d
...
...
@@ -40,12 +40,15 @@
});
socket
.
on
(
'
startGame
'
,
({
board
,
currentPlayer
})
=>
{
const
messages
=
document
.
getElementById
(
'
messages
'
);
messages
.
innerHTML
+=
`<div><strong>Game starting</strong></div>`
;
drawBoard
(
board
);
});
socket
.
on
(
'
end
Game
'
,
()
=>
{
socket
.
on
(
'
stop
Game
'
,
()
=>
{
const
messages
=
document
.
getElementById
(
'
messages
'
);
messages
.
innerHTML
+=
`<div></div>`
;
messages
.
innerHTML
+=
`<div><
strong>Game Finish</strong><
/div>`
;
});
socket
.
on
(
'
updateGame
'
,
({
board
,
currentPlayer
,
winner
})
=>
{
...
...
@@ -62,6 +65,7 @@
function
sendMessage
()
{
const
message
=
document
.
getElementById
(
'
messageInput
'
).
value
;
socket
.
emit
(
'
chatMessage
'
,
message
);
console
.
log
(
"
message sent
"
);
document
.
getElementById
(
'
messageInput
'
).
value
=
''
;
}
...
...
This diff is collapsed.
Click to expand it.
server.js
+
6
−
2
View file @
022a9a2d
...
...
@@ -50,7 +50,7 @@ io.on('connection', (socket) => {
let
stopGame
=
(
room
,
roomId
)
=>
{
console
.
log
(
"
Not enough players in room
"
+
roomId
+
"
, game stops.
"
);
io
.
to
(
roomId
).
emit
(
'
stopGame
'
)
io
.
to
(
roomId
).
emit
(
'
stopGame
'
)
;
};
let
startGame
=
(
room
,
roomId
)
=>
{
...
...
@@ -71,6 +71,7 @@ io.on('connection', (socket) => {
stopGame
(
currentRoom
,
currentRoom
.
id
);
}
console
.
log
(
"
Player
"
+
playerName
+
"
leaved room
"
+
currentRoom
.
id
+
"
.
"
);
socket
.
leave
(
currentRoom
.
id
);
currentRoom
=
null
;
io
.
emit
(
'
updateRooms
'
,
rooms
);
}
...
...
@@ -96,6 +97,8 @@ io.on('connection', (socket) => {
});
io
.
emit
(
'
updateRooms
'
,
rooms
);
socket
.
join
(
roomId
);
io
.
to
(
roomId
).
emit
(
'
updatePlayers
'
,
room
.
players
);
if
(
room
.
players
.
length
===
2
)
{
startGame
(
room
,
roomId
);
...
...
@@ -138,9 +141,9 @@ io.on('connection', (socket) => {
socket
.
on
(
'
chatMessage
'
,
(
message
)
=>
{
if
(
!
currentRoom
)
{
console
.
log
(
"
TEST
"
+
currentRoom
);
return
;
}
console
.
log
(
"
Message
"
+
message
+
"
in room
"
+
currentRoom
.
id
+
"
from
"
+
playerName
);
io
.
to
(
currentRoom
.
id
).
emit
(
'
message
'
,
{
name
:
playerName
,
message
...
...
@@ -148,6 +151,7 @@ io.on('connection', (socket) => {
});
socket
.
on
(
'
disconnect
'
,
()
=>
{
console
.
log
(
"
Player
"
+
playerName
+
"
disconnected
"
);
leaveRooms
();
});
});
...
...
This diff is collapsed.
Click to expand it.
test
0 → 100644
+
0
−
0
View file @
022a9a2d
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