added comments to python code
This commit is contained in:
parent
634f50c3c5
commit
a19a35db79
@ -2,26 +2,39 @@ from flask import Flask
|
|||||||
from flask import render_template, jsonify, request
|
from flask import render_template, jsonify, request
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
games = {}
|
# Since only one game for now, this is the object that will hold the data for the game
|
||||||
game = {}
|
game = {}
|
||||||
|
|
||||||
|
|
||||||
|
# Renders client
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def initial():
|
def initial():
|
||||||
return render_template('index.html')
|
return render_template('index.html')
|
||||||
|
|
||||||
|
# The URL where the data transfer takes place, the "backend"
|
||||||
@app.route('/game', methods=['GET', 'POST'])
|
@app.route('/game', methods=['GET', 'POST'])
|
||||||
def update_game():
|
def update_game():
|
||||||
|
|
||||||
|
# This is for if the Client Wants something
|
||||||
|
# Eventually will be used for initial team and coordinate
|
||||||
|
# Not currently being used anywhere
|
||||||
if request.method == 'GET':
|
if request.method == 'GET':
|
||||||
return jsonify(game)
|
return jsonify(game)
|
||||||
|
|
||||||
|
# What to do when the Client tells the server something
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
|
# Define the data given by client
|
||||||
playerStatus = request.get_json(force=True)
|
playerStatus = request.get_json(force=True)
|
||||||
|
# If the turn that the player sent is already defined in game
|
||||||
if playerStatus["turn"] in game:
|
if playerStatus["turn"] in game:
|
||||||
game[playerStatus["turn"]].append([playerStatus["coordinate"], playerStatus["team"]])
|
game[playerStatus["turn"]].append([playerStatus["coordinate"], playerStatus["team"]])
|
||||||
else:
|
else:
|
||||||
game[playerStatus["turn"]] = [[playerStatus["coordinate"], playerStatus["team"]]]
|
game[playerStatus["turn"]] = [[playerStatus["coordinate"], playerStatus["team"]]]
|
||||||
|
# Return the game with the information you added, in addition to everyone else
|
||||||
return jsonify(game)
|
return jsonify(game)
|
||||||
|
|
||||||
|
|
||||||
|
# Eventual more than one game can be played on website
|
||||||
|
|
||||||
# @app.route('/game/<int:game_id>', methods=['GET', 'POST'])
|
# @app.route('/game/<int:game_id>', methods=['GET', 'POST'])
|
||||||
# def update_game(game_id):
|
# def update_game(game_id):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user