Created
January 18, 2017 22:27
-
-
Save rvegas/e33aecf4a0bcc157bb485e2d15ceeea6 to your computer and use it in GitHub Desktop.
keepcoding webinar 1 - damage.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, request, jsonify | |
import random | |
app = Flask(__name__) | |
app.config['DEBUG'] = True | |
@app.route("/", methods=['GET']) | |
def damage(): | |
base_damage = request.args.get('base_damage', type=float, default=0.0) | |
modifiers = request.args.getlist('modifiers') | |
if 'double_damage' in modifiers: | |
base_damage = base_damage * 2 | |
general_damage_modifier = random.uniform(0.7, 1) | |
if 'true_damage' in modifiers: | |
general_damage_modifier = 1.0 | |
damage = base_damage * general_damage_modifier | |
return jsonify(data={ | |
'damage': damage, | |
'modifiers': modifiers | |
}) | |
if __name__ == "__main__": | |
app.run(host="127.0.0.1") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment