import json from flask import Flask, jsonify from flask_cors import CORS from ebermergen.models.game import Game from .lib import generate_map from .lib.ebermergen_game import EbermergenGame app = Flask(__name__) CORS(app) games = {} @app.route('/') def index(): return 'Hello World' @app.route('/generate') def generate(): return jsonify(generate_map((10, 8))) @app.route('/generate//') def generate_var(x, y): return jsonify(generate_map((x, y))) @app.route('/state') def state(): a = Game() a.seed_map() return jsonify(a.serialize()) @app.route('/lala') def lala(): return jsonify({k: v.state for (k, v) in games.items()}) @app.route('/new-game/', methods=['GET', 'POST']) def new_game(name): games[name] = EbermergenGame() games[name].start_game() return jsonify({'message': 'success'}) @app.route('/action//') def action(name, type): games[name].perform_action(type, {}) return jsonify({'message': 'success'})