add leaderboard
This commit is contained in:
parent
dc26c4281b
commit
dbab510358
9 changed files with 1575 additions and 8 deletions
|
@ -212,7 +212,7 @@ class Game extends GameBasic {
|
|||
|
||||
if (this.entities.length == 0) this.entities = [this.player];
|
||||
}
|
||||
init() {
|
||||
async init() {
|
||||
super.init();
|
||||
|
||||
let that = this;
|
||||
|
@ -229,6 +229,19 @@ class Game extends GameBasic {
|
|||
setInterval(function () { that.render() }, 1000 / 60);
|
||||
|
||||
game.canvas.onclick = () => that.click();
|
||||
|
||||
let jason = await (fetch('/leaderboard').then(x => x.json()))
|
||||
|
||||
let scores = {};
|
||||
|
||||
for (let e of jason) {
|
||||
scores[e.ip] = scores[e.ip] || 0;
|
||||
scores[e.ip] += e.ko ** 2;
|
||||
}
|
||||
|
||||
scores = Object.entries(scores).sort((a,b) => b.ko - a.ko);
|
||||
|
||||
document.querySelector('.lb').textContent = scores.map(x => `${x[0]}: ${x[1]}`).join('\n');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue