return {'tips': game.shown_tips}
-@post('/api/games/<game_id>/finish')
+@post('/api/games/<game_id>/finish/<latitude>/<longitude>')
@enable_cors
-def finish_game(game_id):
+def finish_game(game_id, latitude, longitude):
if not game_id in games:
return bottle.HTTPResponse(status=404, body='game not found')
game = games[game_id]
- answer = request.json
-
- answer_coordinates = (answer["latitude"], answer["longitude"])
+ answer_coordinates = (float(latitude), float(longitude))
d = distance(game.current_coordinates, answer_coordinates)
tips: this.gameController.tips(),
loading: false
}, () => {
- createMap('map');
+ createMap('map', this.onMapClick);
})
}).catch(error => {
this.notification.show(
});
};
+ onMapClick = (e) => {
+ this.gameController.tryFinish(`${e.latlng.lat}/${e.latlng.lng}`).then(json => {
+ this.notification.show(
+ 'Игра закончена.',
+ `Неплохая попытка! Вы оказались по адресу: ${json.data.address}, а промахнулись на ${Math.round(json.data.distance)} метров.`,
+ () => {
+ window.location = '/';
+ }
+ );
+ }).catch(error => {
+ this.notification.show(
+ 'Что-то сломалось, зовите разраба',
+ error && JSON.stringify(error)
+ );
+ });
+ };
+
render() {
if(this.state.loading) {
return (
this._tips = json.data.tips;
});
}
+
+ tryFinish(ltLng) {
+ return api.post(`/games/${this.gameId}/finish/${ltLng}`);
+ }
}
\ No newline at end of file
this.div = div;
}
- show(text, info) {
+ show(text, info, afterHide) {
+ this.afterHide = afterHide;
ReactDOM.render(
<Modal onClose={this.hide} width={600}>
<Modal.Header>{text}</Modal.Header>
hide = () => {
this.div && ReactDOM.render(null, this.div);
+ this.afterHide && this.afterHide();
}
}
\ No newline at end of file
SW: ['56.768982', '60.491112']
};
-export function createMap(elementId) {
+export function createMap(elementId, onMapClick) {
const neLat = ekb.NE[0];
const neLng = ekb.NE[1];
const swLat = ekb.SW[0];
const map = new L.Map(elementId);
+ map.on('click', onMapClick);
+
const service = new L.tileLayer(
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
{