Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
sae-2023-groupeH-Bouin-Belguebli-Decoster
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Julien Bouin
sae-2023-groupeH-Bouin-Belguebli-Decoster
Commits
e4e9752b
Commit
e4e9752b
authored
1 year ago
by
Julien Bouin
Browse files
Options
Downloads
Patches
Plain Diff
refactor index
parent
90559b03
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
client/src/scoreboard.json
+17
-73
17 additions, 73 deletions
client/src/scoreboard.json
server/ScoreBoard.js
+0
-2
0 additions, 2 deletions
server/ScoreBoard.js
server/index.js
+203
-122
203 additions, 122 deletions
server/index.js
with
220 additions
and
197 deletions
client/src/scoreboard.json
+
17
−
73
View file @
e4e9752b
{
"results"
:
[
{
"nom"
:
"julien"
,
"score"
:
-15
},
{
"nom"
:
"julien"
,
"score"
:
-15
},
{
"nom"
:
"julien"
,
"score"
:
-15
},
{
"nom"
:
"julien2"
,
"score"
:
-10
},
{
"nom"
:
"j"
,
"score"
:
-10
},
{
"nom"
:
"test"
,
"score"
:
-15
},
{
"nom"
:
"pierre"
,
"score"
:
20
...
...
@@ -33,89 +9,57 @@
"score"
:
-15
},
{
"nom"
:
"p"
,
"score"
:
30
},
{
"nom"
:
"pp"
,
"score"
:
-15
},
{
"nom"
:
"ma"
,
"score"
:
70
},
{
"nom"
:
"ppapa"
,
"score"
:
40
},
{
"nom"
:
"mm"
,
"score"
:
55
},
{
"score"
:
-15
},
{
"nom"
:
"testtt"
,
"score"
:
-15
},
{
"score"
:
-5
},
{
"nom"
:
"test"
,
"nom"
:
"m"
,
"score"
:
-15
},
{
"nom"
:
"m"
,
"score"
:
2
0
"score"
:
0
},
{
"nom"
:
"m
`
"
,
"score"
:
-15
"nom"
:
"m"
,
"score"
:
0
},
{
"nom"
:
"
p
"
,
"score"
:
5
"nom"
:
"
anne
"
,
"score"
:
-
5
},
{
"nom"
:
"
m
"
,
"score"
:
-
25
"nom"
:
"
test2
"
,
"score"
:
-
10
},
{
"nom"
:
"test"
,
"score"
:
-10
"score"
:
-15
},
{
"nom"
:
"p"
,
"score"
:
-15
},
{
"nom"
:
"
^
"
,
"nom"
:
"
ff
"
,
"score"
:
-15
},
{
"nom"
:
"
m
"
,
"nom"
:
"
test2
"
,
"score"
:
-5
},
{
"nom"
:
"
tes
"
,
"nom"
:
"
mama
"
,
"score"
:
-15
},
{
"score"
:
-10
"nom"
:
"te"
,
"score"
:
-20
},
{
"nom"
:
"
p
"
,
"nom"
:
"
f
"
,
"score"
:
0
},
{
"nom"
:
"m"
,
"score"
:
5
},
{
"nom"
:
"p"
,
"score"
:
-10
"nom"
:
"f"
,
"score"
:
-15
}
]
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
server/ScoreBoard.js
+
0
−
2
View file @
e4e9752b
...
...
@@ -10,13 +10,11 @@ export class GestionScore {
const
data
=
fs
.
readFileSync
(
this
.
jsonFilePath
);
const
scores
=
JSON
.
parse
(
data
);
// Trier les scores par ordre décroissant
scores
.
results
.
sort
((
a
,
b
)
=>
b
.
score
-
a
.
score
);
let
html
=
'
<table><thead><tr><th>Nom</th><th>Score</th></tr></thead><tbody>
'
;
// Afficher les 10 premiers résultats
const
numberOfResults
=
Math
.
min
(
10
,
scores
.
results
.
length
);
for
(
let
i
=
0
;
i
<
numberOfResults
;
i
++
)
{
const
result
=
scores
.
results
[
i
];
...
...
This diff is collapsed.
Click to expand it.
server/index.js
+
203
−
122
View file @
e4e9752b
...
...
@@ -46,7 +46,7 @@ const avatars = [];
const
enemis
=
[];
const
bonusArray
=
[];
let
cpt
=
0
;
let
cpt
Connexion
=
0
;
let
canShoot
=
true
;
let
LVL2start
=
false
;
let
LVL3start
=
false
;
...
...
@@ -55,62 +55,100 @@ const gestionScore = new GestionScore('client/src/scoreboard.json');
let
scores
=
gestionScore
.
afficherScores
();
io
.
on
(
'
connection
'
,
socket
=>
{
cpt
++
;
if
(
cpt
<=
4
)
{
cptConnexion
++
;
if
(
cptConnexion
<=
4
)
{
firstAvatar
=
true
;
const
avatar
=
new
Avatar
(
`
${
socket
.
id
}
`
,
cpt
);
io
.
emit
(
'
newAvatar
'
,
{
id
:
cpt
,
x
:
avatar
.
getX
(),
y
:
avatar
.
getY
()
});
avatars
.
push
(
avatar
);
socket
.
on
(
'
pseudo
'
,
pseudo
=>
{
avatar
.
pseudo
=
pseudo
;
const
avatar
=
createAvatar
(
socket
);
io
.
emit
(
'
newAvatar
'
,
{
id
:
cptConnexion
,
x
:
avatar
.
getX
(),
y
:
avatar
.
getY
(),
});
handlePseudonym
(
socket
,
avatar
);
io
.
emit
(
'
scores
'
,
scores
);
socket
.
on
(
'
disconnect
'
,
()
=>
{
avatars
.
forEach
(
avatar
=>
{
if
(
avatar
.
nom
==
socket
.
id
)
{
io
.
emit
(
'
disconnectEvent
'
,
avatar
.
id
);
avatars
.
splice
(
avatars
.
indexOf
(
avatar
),
1
);
}
});
console
.
log
(
`Déconnexion du client
${
socket
.
id
}
`
);
});
handleDisconnect
(
socket
);
socket
.
on
(
'
start
'
,
s
=>
{
if
(
s
==
true
&&
cpt
!=
0
)
{
gameStarted
=
s
;
}
else
if
(
cpt
==
0
)
{
gameStarted
=
false
;
}
});
handleGameStart
(
socket
);
socket
.
on
(
'
clickEvent
'
,
clickEvent
=>
{
const
playerAvatar
=
avatars
.
find
(
avatar
=>
avatar
.
nom
===
clickEvent
.
id
);
if
(
playerAvatar
)
{
playerAvatar
.
click
[
clickEvent
.
key
]
=
clickEvent
.
pressed
;
}
else
{
console
.
log
(
`Aucun avatar trouvé avec le nom
${
clickEvent
.
id
}
`
);
}
});
handleClickEvents
(
socket
);
socket
.
on
(
'
shoot
'
,
shoot
=>
{
const
playerAvatar
=
avatars
.
find
(
avatar
=>
avatar
.
nom
===
shoot
.
id
);
handleShooting
(
socket
);
if
(
canShoot
)
{
playerAvatar
.
tirer
();
canShoot
=
false
;
setTimeout
(
function
()
{
canShoot
=
true
;
},
200
);
handleCanvasSize
(
socket
);
}
});
function
createAvatar
(
socket
)
{
const
avatar
=
new
Avatar
(
`
${
socket
.
id
}
`
,
cptConnexion
);
avatars
.
push
(
avatar
);
return
avatar
;
}
function
handlePseudonym
(
socket
,
avatar
)
{
socket
.
on
(
'
pseudo
'
,
pseudo
=>
{
avatar
.
pseudo
=
pseudo
;
});
}
function
handleDisconnect
(
socket
)
{
socket
.
on
(
'
disconnect
'
,
()
=>
{
avatars
.
forEach
(
avatar
=>
{
if
(
avatar
.
nom
==
socket
.
id
)
{
io
.
emit
(
'
disconnectEvent
'
,
avatar
.
id
);
avatars
.
splice
(
avatars
.
indexOf
(
avatar
),
1
);
}
});
console
.
log
(
`Déconnexion du client
${
socket
.
id
}
`
);
});
}
socket
.
on
(
'
canvasSize
'
,
canvasSize
=>
{
console
.
log
(
canvasSize
);
canvasSize
=
canvasSize
;
});
}
});
function
handleGameStart
(
socket
)
{
socket
.
on
(
'
start
'
,
s
=>
{
if
(
s
==
true
&&
cptConnexion
!=
0
)
{
gameStarted
=
s
;
}
else
if
(
cptConnexion
==
0
)
{
gameStarted
=
false
;
}
});
}
function
handleClickEvents
(
socket
)
{
socket
.
on
(
'
clickEvent
'
,
clickEvent
=>
{
const
playerAvatar
=
avatars
.
find
(
avatar
=>
avatar
.
nom
===
clickEvent
.
id
);
if
(
playerAvatar
)
{
playerAvatar
.
click
[
clickEvent
.
key
]
=
clickEvent
.
pressed
;
}
else
{
console
.
log
(
`Aucun avatar trouvé avec le nom
${
clickEvent
.
id
}
`
);
}
});
}
function
handleShooting
(
socket
)
{
socket
.
on
(
'
shoot
'
,
shoot
=>
{
const
playerAvatar
=
avatars
.
find
(
avatar
=>
avatar
.
nom
===
shoot
.
id
);
if
(
canShoot
)
{
playerAvatar
.
tirer
();
canShoot
=
false
;
setTimeout
(
function
()
{
canShoot
=
true
;
},
200
);
}
});
}
function
handleCanvasSize
(
socket
)
{
socket
.
on
(
'
canvasSize
'
,
size
=>
{
console
.
log
(
size
);
canvasSize
=
size
;
});
}
let
spawnIntervalLV1
=
setInterval
(()
=>
{
if
(
gameStarted
)
{
...
...
@@ -163,71 +201,31 @@ let spawnBonusInterval = setInterval(() => {
},
15000
);
setInterval
(()
=>
{
scores
=
gestionScore
.
afficher
Scores
();
io
.
emit
(
'
scores
'
,
scores
);
update
Scores
();
io
.
emit
(
'
enemis
'
,
enemis
);
io
.
emit
(
'
bonusArray
'
,
bonusArray
);
le
t
areAvatarsActive
=
avatars
.
some
(
avatar
=>
!
avatar
.
spectateur
);
cons
t
areAvatarsActive
=
avatars
.
some
(
avatar
=>
!
avatar
.
spectateur
);
// Si des avatars sont actifs
if
(
firstAvatar
&&
areAvatarsActive
)
{
let
avatarData
=
[];
const
avatarData
=
[];
avatars
.
forEach
(
avatar
=>
{
avatar
.
canvasSize
=
canvasSize
;
if
(
avatar
.
getStatut
()
==
'
invincibilite
'
&&
t
.
getTotalTime
()
-
avatar
.
getStatutTime
()
==
15
)
{
avatar
.
setStatut
(
'
null
'
);
}
enemis
.
forEach
(
enemi
=>
{
if
(
enemi
.
hitbox
.
colision
(
avatar
.
hitbox
)
&&
avatar
.
getStatut
()
!=
'
invincibilite
'
&&
!
avatar
.
spectateur
)
{
if
(
canLostLifeAvatar
)
{
avatar
.
decrementScore
(
5
);
enemis
.
splice
(
enemis
.
indexOf
(
enemi
),
1
);
avatar
.
perdreVie
();
canLostLifeAvatar
=
false
;
setTimeout
(
function
()
{
canLostLifeAvatar
=
true
;
},
100
);
}
if
(
avatar
.
getVies
()
==
0
)
{
gestionScore
.
ajouterScore
(
avatar
.
pseudo
,
avatar
.
score
);
avatar
.
setSpectateur
();
io
.
emit
(
'
dead
'
,
avatar
.
id
);
}
}
enemi
.
deplacer
();
avatar
.
colision
(
enemi
.
hitbox
);
avatar
.
projectiles
.
forEach
(
projectile
=>
{
if
(
projectile
.
hitbox
.
colision
(
enemi
.
hitbox
))
{
if
(
enemi
.
getVies
()
<
0
)
{
console
.
log
(
avatar
.
id
);
avatar
.
incrementScore
(
5
);
enemis
.
splice
(
enemis
.
indexOf
(
enemi
),
1
);
}
avatar
.
projectiles
.
splice
(
avatar
.
projectiles
.
indexOf
(
projectile
),
1
);
if
(
canLostLifeEnemi
)
{
enemi
.
perdreVie
();
canLostLifeEnemi
=
false
;
setTimeout
(
function
()
{
canLostLifeEnemi
=
true
;
},
1000
/
60
);
}
}
});
});
avatar
.
deplacer
();
avatar
.
projectiles
.
forEach
(
projectile
=>
projectile
.
deplacer
());
updateInvincibilityStatus
(
avatar
);
handleAvatarEnemyCollisions
(
avatar
);
moveEnemies
();
handleAvatarProjectileCollisions
(
avatar
);
moveAvatarsAndProjectiles
(
avatar
);
if
(
!
avatar
.
spectateur
)
{
avatarData
.
push
({
id
:
avatar
.
id
,
...
...
@@ -239,27 +237,110 @@ setInterval(() => {
socketId
:
avatar
.
nom
,
});
}
bonusArray
.
forEach
(
bonus
=>
{
if
(
bonus
.
hitbox
.
colision
(
avatar
.
hitbox
))
{
if
(
bonusNoms
[
bonus
.
getChoix
()]
==
'
vie
'
)
{
avatar
.
gagnerVie
();
}
else
if
(
bonusNoms
[
bonus
.
getChoix
()]
==
'
invincibilite
'
)
{
avatar
.
setStatut
(
'
invincibilite
'
);
avatar
.
setStatutTime
(
t
.
getTotalTime
());
}
bonusArray
.
splice
(
bonusArray
.
indexOf
(
bonus
),
1
);
}
if
(
bonus
.
estExpire
(
t
.
getTotalTime
()))
{
bonusArray
.
splice
(
bonusArray
.
indexOf
(
bonus
),
1
);
}
});
handleAvatarBonusCollisions
(
avatar
);
});
io
.
emit
(
'
avatarsData
'
,
avatarData
);
}
else
{
gameStarted
=
false
;
cpt
=
0
;
t
=
new
timer
();
avatars
.
length
=
0
;
// Réinitialiser le tableau d'avatars
io
.
emit
(
'
endGame
'
,
true
);
stopGame
();
}
},
1000
/
60
);
function
updateScores
()
{
scores
=
gestionScore
.
afficherScores
();
io
.
emit
(
'
scores
'
,
scores
);
}
function
updateInvincibilityStatus
(
avatar
)
{
if
(
avatar
.
getStatut
()
==
'
invincibilite
'
&&
t
.
getTotalTime
()
-
avatar
.
getStatutTime
()
==
15
)
{
avatar
.
setStatut
(
'
null
'
);
}
}
function
handleAvatarEnemyCollisions
(
avatar
)
{
enemis
.
forEach
(
enemi
=>
{
if
(
enemi
.
hitbox
.
colision
(
avatar
.
hitbox
)
&&
avatar
.
getStatut
()
!=
'
invincibilite
'
&&
!
avatar
.
spectateur
)
{
if
(
canLostLifeAvatar
)
{
avatar
.
decrementScore
(
5
);
enemis
.
splice
(
enemis
.
indexOf
(
enemi
),
1
);
avatar
.
perdreVie
();
canLostLifeAvatar
=
false
;
setTimeout
(
function
()
{
canLostLifeAvatar
=
true
;
},
100
);
}
if
(
avatar
.
getVies
()
==
0
)
{
gestionScore
.
ajouterScore
(
avatar
.
pseudo
,
avatar
.
score
);
avatar
.
setSpectateur
();
io
.
emit
(
'
dead
'
,
avatar
.
id
);
}
}
});
}
function
moveEnemies
()
{
enemis
.
forEach
(
enemi
=>
{
enemi
.
deplacer
();
});
}
function
handleAvatarProjectileCollisions
(
avatar
)
{
enemis
.
forEach
(
enemi
=>
{
avatar
.
projectiles
.
forEach
(
projectile
=>
{
if
(
projectile
.
hitbox
.
colision
(
enemi
.
hitbox
))
{
if
(
enemi
.
getVies
()
<
0
)
{
avatar
.
incrementScore
(
5
);
enemis
.
splice
(
enemis
.
indexOf
(
enemi
),
1
);
}
avatar
.
projectiles
.
splice
(
avatar
.
projectiles
.
indexOf
(
projectile
),
1
);
if
(
canLostLifeEnemi
)
{
enemi
.
perdreVie
();
canLostLifeEnemi
=
false
;
setTimeout
(
function
()
{
canLostLifeEnemi
=
true
;
},
1000
/
60
);
}
}
});
});
}
function
moveAvatarsAndProjectiles
(
avatar
)
{
avatar
.
deplacer
();
avatar
.
projectiles
.
forEach
(
projectile
=>
{
projectile
.
deplacer
();
});
}
function
handleAvatarBonusCollisions
(
avatar
)
{
bonusArray
.
forEach
(
bonus
=>
{
if
(
bonus
.
hitbox
.
colision
(
avatar
.
hitbox
))
{
if
(
bonusNoms
[
bonus
.
getChoix
()]
==
'
vie
'
)
{
avatar
.
gagnerVie
();
}
else
if
(
bonusNoms
[
bonus
.
getChoix
()]
==
'
invincibilite
'
)
{
avatar
.
setStatut
(
'
invincibilite
'
);
avatar
.
setStatutTime
(
t
.
getTotalTime
());
}
bonusArray
.
splice
(
bonusArray
.
indexOf
(
bonus
),
1
);
}
if
(
bonus
.
estExpire
(
t
.
getTotalTime
()))
{
bonusArray
.
splice
(
bonusArray
.
indexOf
(
bonus
),
1
);
}
});
}
function
stopGame
()
{
gameStarted
=
false
;
cptConnexion
=
0
;
t
=
new
timer
();
avatars
.
length
=
0
;
io
.
emit
(
'
endGame
'
,
true
);
}
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