diff --git a/traque-back/game.js b/traque-back/game.js index 2dd7fe7..bd99ff1 100644 --- a/traque-back/game.js +++ b/traque-back/game.js @@ -27,7 +27,11 @@ export default class Game { } this.initLastSentLocations(); this.zone.reset() - this.zone.start() + //If the zone cannot be setup, reset everything + if(!this.zone.start()) { + this.setState(GameState.SETUP); + return; + } } if (newState != GameState.PLAYING) { this.zone.reset(); diff --git a/traque-back/zone_manager.js b/traque-back/zone_manager.js index edf68de..464ddb8 100644 --- a/traque-back/zone_manager.js +++ b/traque-back/zone_manager.js @@ -108,7 +108,8 @@ export class ZoneManager { this.nextZone = JSON.parse(JSON.stringify(this.zoneSettings.max)); this.currentStartZone = JSON.parse(JSON.stringify(this.zoneSettings.max)); this.currentZone = JSON.parse(JSON.stringify(this.zoneSettings.max)); - this.setNextZone(); + return this.setNextZone(); + } /** @@ -121,11 +122,16 @@ export class ZoneManager { getRandomNextCenter(newRadius) { let ok = false; let res = null + let tries = 0; + const MAX_TRIES = 1000 //take a random point satisfying both conditions - while (!ok) { + while (tries++=MAX_TRIES) { + return false; + } return { lat: res.latitude, lng: res.longitude