Skip to content

Commit

Permalink
refactor and fix sorted in scoreboard
Browse files Browse the repository at this point in the history
  • Loading branch information
pelazas committed Apr 3, 2024
1 parent 8c23ba0 commit 602534a
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 19 deletions.
2 changes: 1 addition & 1 deletion webapp/src/components/game/ScoreboardGame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const ScoreboardGame:FC<ScoreboardGameProps> = ({userScoresSinglePlayer, userSco
if(userScoresSinglePlayer){
sorted = userScoresSinglePlayer.sort((a, b) => b.points - a.points);
} else if (userScoresMultiPlayer){
sorted = userScoresMultiPlayer;
sorted = userScoresMultiPlayer.sort((a, b) => b.points - a.points);
}
return (
<section>
Expand Down
7 changes: 0 additions & 7 deletions webapp/src/components/game/multiplayer/GameMultiPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,30 +50,23 @@ const GameMultiPlayer: FC<GameMultiPlayerProps> = () => {
});

newSocket.on('joinedParty', (user: UserPlayer) => {
console.log(user)
console.log(`User ${username} joined the party`);
setStage(2);
console.log(users)
})

newSocket.on('lobbyUsers', (users: UserPlayer[]) => {
setUsers(users);
console.log(users)
});

newSocket.on('partyNotFound', () => {
console.log('Party not found');
});

newSocket.on('allPlayersFinished', (playersWithPoints:PlayerWithPoints[]) => {
console.log(playersWithPoints)
setSortedUsersByPoints(playersWithPoints);
setStage(4);
})

newSocket.on('questionsUpdated', (questions: Question4Answers[]) => {
console.log('questions recieved from server')
console.log(questions);
setQuestions(questions);
setStage(3);
})
Expand Down
5 changes: 0 additions & 5 deletions webapp/src/components/game/multiplayer/LobbyMultiPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,11 @@ const LobbyMultiPlayer: FC<LobbyMultiPlayerProps> = ({socket, handleCurrentStage
const apiEndpoint = process.env.REACT_APP_API_ENDPOINT || 'http://localhost:8000';

try {
console.log(users)
const requestData = {
players: users.map((user) => ({uuid: user.uuid}))
}
console.log("requestData")
console.log(requestData)
const response = await axios.post(`${apiEndpoint}/createGame`, requestData);

console.log("Juego creado")
console.log(response.data)
socket.emit('updateQuestions', partyCode, response.data);
setFetched(true);
} catch (error) {
Expand Down
3 changes: 0 additions & 3 deletions webapp/src/components/game/multiplayer/MenuMultiplayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ const MenuMultiplayer: FC<MenuMultiplayerProps> = ({socket, handleCurrentStage,
};

const joinParty = () => {
console.log("Joining party...")
console.log(typedCode)
console.log(username)
const user: UserPlayer = {
username: username,
totalPoints: parseInt(totalPoints),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,9 @@ const QuestionsMultiPlayer: FC<QuestionsMultiPlayerProps> = ({socket, questions,

}
setCurrentQuestion(currentQuestion + 1);
console.log(currentQuestion+2)
console.log(questions.length)
if(currentQuestion+2 === questions.length){
const totalPoints = calculatePoints(correctAnswers, questions.length);
// the player has finished the game
console.log("finish")
// update stats for each player
const requestData ={ "players": [{
"uuid": uuid,
Expand Down

0 comments on commit 602534a

Please sign in to comment.