diff --git a/socket/src/utils/round.js b/socket/src/utils/round.js index 7e9eae1..728c671 100644 --- a/socket/src/utils/round.js +++ b/socket/src/utils/round.js @@ -73,10 +73,9 @@ export const startRound = async (game, io, socket) => { game.players.find((p) => p.id === player.id).points += points setTimeout(() => { - let rank = - game.players - .sort((a, b) => b.points - a.points) - .findIndex((p) => p.id === player.id) + 1 + let sortPlayers = game.players.sort((a, b) => b.points - a.points) + + let rank = sortPlayers.findIndex((p) => p.id === player.id) + 1 io.to(player.id).emit("game:status", { name: "SHOW_RESULT", @@ -86,7 +85,10 @@ export const startRound = async (game, io, socket) => { points: points, myPoints: player.points, totalPlayer: game.players.length, - rank: rank, + rank, + aheadOfMe: sortPlayers[rank - 2] + ? sortPlayers[rank - 2].username + : null, }, }) }, 200) diff --git a/src/components/game/states/Answers.jsx b/src/components/game/states/Answers.jsx index 6d17e6f..50cff8f 100644 --- a/src/components/game/states/Answers.jsx +++ b/src/components/game/states/Answers.jsx @@ -99,12 +99,12 @@ export default function Answers({
{!responses && ( -
-
+
+
Time {cooldown}
-
+
Answers {totalAnswer}
diff --git a/src/components/game/states/Question.jsx b/src/components/game/states/Question.jsx index 8cfe37e..f61a9a5 100644 --- a/src/components/game/states/Question.jsx +++ b/src/components/game/states/Question.jsx @@ -7,7 +7,7 @@ export default function Question({ data: { question } }) { return (
-

+

{question}

diff --git a/src/components/game/states/Result.jsx b/src/components/game/states/Result.jsx index 1904fe8..f9ed4e6 100644 --- a/src/components/game/states/Result.jsx +++ b/src/components/game/states/Result.jsx @@ -4,7 +4,7 @@ import { usePlayerContext } from "@/context/player" import { useEffect } from "react" export default function Result({ - data: { correct, message, points, myPoints, totalPlayer, rank }, + data: { correct, message, points, myPoints, totalPlayer, rank, aheadOfMe }, }) { const { dispatch } = usePlayerContext() @@ -25,6 +25,9 @@ export default function Result({

{message}

+

+ {`You are top ${rank}` + (aheadOfMe ? ", behind " + aheadOfMe : "")} +

{correct && ( +{points}