diff --git a/client/src/components/Game.vue b/client/src/components/Game.vue index e279e3a..53cfec5 100644 --- a/client/src/components/Game.vue +++ b/client/src/components/Game.vue @@ -21,6 +21,7 @@ export default { x: 0, y: 0 }, + leaderboard: [], renderTimer: null } }, @@ -71,6 +72,11 @@ export default { if (!this.players) return + this.players.sort((a, b) => { + return a.walls.length - b.walls.length + }) + this.leaderboard = [] + this.players.forEach(player => { if (player.color === this.player.color) { this.camera.x = player.x @@ -79,7 +85,10 @@ export default { } this.renderPlayer(player) this.renderWalls(player) + this.leaderboard.push(player.id + ' - ' + player.walls.length) }) + + this.renderLeaderboard() }, renderBorders () { this.context.strokeStyle = 'black' @@ -116,10 +125,11 @@ export default { const canvasX = this.canvas.width / 2 const canvasY = this.canvas.height / 2 - this.context.fillText('player x: ' + player.x + ' y:' + player.y, 10, 10) - this.context.fillText('a:' + player.angle + ' a_t' + player.targetAngle, 10, 20) - this.context.fillText('canvasX: ' + canvasX + ' canvasY:' + canvasY, 10, 30) - this.context.fillText('walls: ' + player.walls.length, 10, 40) + this.context.textAlign = 'start' + this.context.fillText('player x: ' + player.x + ' y:' + player.y, 10, 12) + this.context.fillText('a:' + player.angle + ' a_t' + player.targetAngle, 10, 24) + this.context.fillText('canvasX: ' + canvasX + ' canvasY:' + canvasY, 10, 36) + this.context.fillText('walls: ' + player.walls.length, 10, 48) this.context.beginPath() this.context.arc(this.mouse.x, this.mouse.y, 25, 0, 2 * Math.PI, false) @@ -127,6 +137,13 @@ export default { this.context.strokeStyle = player.color this.context.stroke() }, + renderLeaderboard () { + this.context.textAlign = 'end' + this.context.fillText('Leaderboard: ', this.canvas.width - 50, 10) + for (var i = 0; i < this.leaderboard.length; i++) { + this.context.fillText(this.players[i].color + ' - ' + this.players[i].walls.length, this.canvas.width - 50, 15 + (i + 1) * 10) + } + }, mouseEvent (event) { var rect = this.canvas.getBoundingClientRect() this.mouse.x = event.clientX - rect.left diff --git a/server/src/main/java/gltronic/tronio/business/GameManager.java b/server/src/main/java/gltronic/tronio/business/GameManager.java index dc22812..2094342 100644 --- a/server/src/main/java/gltronic/tronio/business/GameManager.java +++ b/server/src/main/java/gltronic/tronio/business/GameManager.java @@ -134,7 +134,6 @@ public class GameManager implements IGameManager { SocketUtils.sendObject(game.getSessions().get(id), "gamePlayerDead", new ObjectMapper().writeValueAsString(player)); } catch (JsonProcessingException e) { - // TODO Auto-generated catch block e.printStackTrace(); } } @@ -149,20 +148,12 @@ public class GameManager implements IGameManager { } private boolean isCrossingLine (double xa, double ya, double xb, double yb, double xc, double yc, double radius) { - /* - var a = xc - xa; - var b = xb - xa; - var c = yc - ya; - var d = yb - ya; - var result = (a * d - b * c) / Math.sqrt(Math.pow(xa - xb, 2) + Math.pow(ya - yb, 2)); - */ - - var result = Math.abs((yb - ya) * xc - (xb - xa) * yc + xb * ya - yb * xa)/ Math.sqrt(Math.pow(xb - xa, 2) + Math.pow(yb - ya, 2)); + var result = Math.abs((yb - ya) * xc - (xb - xa) * yc + xb * ya - yb * xa) / Math.sqrt(Math.pow(xb - xa, 2) + Math.pow(yb - ya, 2)); return result < radius; } - private Player initPlayer(Player player) { + private Player initPlayer (Player player) { Random rand = new Random(); double x = game.getSettings().getArenaSize() * (0.25 + Math.random() * 0.5); double y = game.getSettings().getArenaSize() * (0.25 + Math.random() * 0.5); diff --git a/server/src/main/java/gltronic/tronio/model/GameEntity.java b/server/src/main/java/gltronic/tronio/model/GameEntity.java deleted file mode 100644 index d9b0753..0000000 --- a/server/src/main/java/gltronic/tronio/model/GameEntity.java +++ /dev/null @@ -1,5 +0,0 @@ -package gltronic.tronio.model; - -public abstract class GameEntity { - -} \ No newline at end of file diff --git a/server/target/classes/gltronic/tronio/business/GameManager.class b/server/target/classes/gltronic/tronio/business/GameManager.class index 838bc43..dc4a148 100644 Binary files a/server/target/classes/gltronic/tronio/business/GameManager.class and b/server/target/classes/gltronic/tronio/business/GameManager.class differ diff --git a/server/target/classes/gltronic/tronio/model/GameEntity.class b/server/target/classes/gltronic/tronio/model/GameEntity.class deleted file mode 100644 index 8dde7df..0000000 Binary files a/server/target/classes/gltronic/tronio/model/GameEntity.class and /dev/null differ