-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLeaderboardManager.ts
33 lines (26 loc) · 1.12 KB
/
LeaderboardManager.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import * as hz from 'horizon/core';
class LeaderboardManager extends hz.Component<typeof LeaderboardManager> {
static propsDefinition = {
// Define any properties needed here
};
private leaderboard: Map<hz.Player, number> = new Map();
start() {
// This method is required for initializing your component
console.log('LeaderboardManager has started.');
}
public addPlayerToLeaderboard(player: hz.Player, matchTime: number) {
// Add the player to the leaderboard with the specified time
console.log(`Adding player ${player.name.get()} with time: ${matchTime}`);
this.leaderboard.set(player, matchTime);
}
public updateLeaderboard() {
console.log('Updating leaderboard...');
// Sort players by their match times in ascending order
const sortedLeaderboard = Array.from(this.leaderboard.entries()).sort((a, b) => a[1] - b[1]);
// Display the leaderboard information in the console
sortedLeaderboard.forEach((entry, index) => {
console.log(`${index + 1}. Player: ${entry[0].name.get()}, Time: ${entry[1]} seconds`);
});
}
}
hz.Component.register(LeaderboardManager);