From 69d03b9d8037f3e2aac54eeff09789a3182fed14 Mon Sep 17 00:00:00 2001 From: folex <0xdxdy@gmail.com> Date: Wed, 26 Jun 2019 18:33:39 +0300 Subject: [PATCH] register new player --- src/components/Game.vue | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/components/Game.vue b/src/components/Game.vue index 5eba340..4ce0ed8 100644 --- a/src/components/Game.vue +++ b/src/components/Game.vue @@ -68,7 +68,7 @@ function getPlayerId() { playerId = getRandomInt(0, 9999999); window.localStorage.setItem("game", playerId); } - return playerId; + return playerId.toString(); } export default { data(){ @@ -103,7 +103,6 @@ export default { window.session.request(`SELECT * FROM enemies`).result().then((r)=>{ var val = r.asString().split("\n").map(i => i.split(", ")) val.splice(0, 1) - console.log(r) this.enemies = [] if(val.length <= 1){ let id = randomInteger(500, 2000000) @@ -135,19 +134,24 @@ export default { }, getPlayers: function() { window.session.request(`SELECT * FROM players`).result().then((r)=>{ - console.log(r.asString()) var val = r.asString().split("\n").map(i => i.split(", ")) val.splice(0, 1) this.players = [] - console.log(val) + val.forEach(v=>{ - console.log(v) - if(v&&v[0]!==this.playerId){ - this.players.push({ + function emptyPlayer(player) { + return v[1] == 0 && v[2] == 0 && v[3] == 0; + } + if(v && v[0] !== this.playerId && !emptyPlayer(v)){ + let player = { left: v[1], top: v[2], angle: v[3] - }) + }; + + console.log(`player: ${v[0]} ${JSON.stringify(player)}`) + + this.players.push(player); } }) setTimeout(()=>this.getPlayers(), 500) @@ -179,6 +183,10 @@ export default { let money = parseInt(r.asString().split("\n")[1]) if (!isNaN(money) && !isNullOrUndefined(money)) { this.money = money + } else { + console.log(`creating new player ${this.playerId}`) + window.session.request(`INSERT INTO users VALUES (${this.playerId}, ${this.playerId}, ${this.money})`) + window.session.request(`INSERT INTO players VALUES (${this.playerId}, 0, 0, 0)`) } console.log(`cash for ${this.playerId} is ${this.money}`) }) @@ -234,9 +242,7 @@ export default { if(v.hp - 10 <= 0){ this.enemies.splice(j, 1) window.session.request(`DELETE FROM ENEMIES WHERE id = ${v.id}`) - console.log('killed') this.money += 10 - console.log("SETTING CASH TO " + this.money + " GAME IS " + this.playerId) window.session.request(`UPDATE users SET cash = ${this.money} WHERE id = ${this.playerId}`) this.level = this.level>5?5:this.level + 1 for(let l=0; l