You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1013 B
Python
54 lines
1013 B
Python
5 years ago
|
import json
|
||
|
from flask import Flask, jsonify
|
||
5 years ago
|
from flask_cors import CORS
|
||
5 years ago
|
|
||
5 years ago
|
from ebermergen.models.game import Game
|
||
5 years ago
|
from .lib import generate_map
|
||
5 years ago
|
|
||
5 years ago
|
from .lib.ebermergen_game import EbermergenGame
|
||
|
|
||
5 years ago
|
app = Flask(__name__)
|
||
5 years ago
|
CORS(app)
|
||
5 years ago
|
|
||
5 years ago
|
games = {}
|
||
|
|
||
5 years ago
|
|
||
|
@app.route('/')
|
||
|
def index():
|
||
|
return 'Hello World'
|
||
5 years ago
|
|
||
|
|
||
|
@app.route('/generate')
|
||
|
def generate():
|
||
5 years ago
|
return jsonify(generate_map((10, 8)))
|
||
5 years ago
|
|
||
|
|
||
|
@app.route('/generate/<int:x>/<int:y>')
|
||
|
def generate_var(x, y):
|
||
5 years ago
|
return jsonify(generate_map((x, y)))
|
||
|
|
||
|
|
||
|
@app.route('/state')
|
||
|
def state():
|
||
|
a = Game()
|
||
|
a.seed_map()
|
||
|
return jsonify(a.serialize())
|
||
5 years ago
|
|
||
|
|
||
|
@app.route('/lala')
|
||
|
def lala():
|
||
|
return jsonify({k: v.state for (k, v) in games.items()})
|
||
|
|
||
|
|
||
|
@app.route('/new-game/<name>', methods=['GET', 'POST'])
|
||
|
def new_game(name):
|
||
|
games[name] = EbermergenGame()
|
||
|
games[name].start_game()
|
||
|
return jsonify({'message': 'success'})
|
||
|
|
||
|
|
||
|
@app.route('/action/<name>/<type>')
|
||
|
def action(name, type):
|
||
|
games[name].perform_action(type, {})
|
||
|
return jsonify({'message': 'success'})
|