add features
This commit is contained in:
+32
-3
@@ -2,7 +2,7 @@ import eventlet
|
||||
|
||||
eventlet.monkey_patch()
|
||||
|
||||
from flask import Flask, jsonify
|
||||
from flask import Flask, jsonify, request
|
||||
from flask_cors import CORS
|
||||
from flask_socketio import SocketIO
|
||||
|
||||
@@ -12,11 +12,40 @@ socketio = SocketIO(app, cors_allowed_origins="*")
|
||||
|
||||
|
||||
game_state = {
|
||||
"gameActive": True,
|
||||
"players": ["Alice", "Bob", "Charlie"],
|
||||
"gameActive": False,
|
||||
"players": [],
|
||||
"playerTurn": 0
|
||||
}
|
||||
|
||||
@app.route("/add", methods=["POST"])
|
||||
def add_player():
|
||||
data = request.get_json()
|
||||
if not data:
|
||||
return jsonify({"error": "No JSON body received"}), 400
|
||||
|
||||
name = data.get("name")
|
||||
group = data.get("group")
|
||||
|
||||
if not name or group not in ["stripes", "solids"]:
|
||||
return jsonify({"error": "Invalid data"}), 400
|
||||
|
||||
game_state["players"].append({"name": name, "group": group})
|
||||
|
||||
# emit socket update
|
||||
socketio.emit("player_update", {"players": game_state["players"]})
|
||||
|
||||
return jsonify({"message": f"Player {name} added to {group} group"})
|
||||
|
||||
@app.route("/reset", methods=["GET"])
|
||||
def reset():
|
||||
game_state = {
|
||||
"gameActive": False,
|
||||
"players": [""],
|
||||
"playerTurn": 0
|
||||
}
|
||||
return jsonify(game_state)
|
||||
|
||||
|
||||
@app.route("/status", methods=["GET"])
|
||||
def status():
|
||||
return jsonify(game_state)
|
||||
|
||||
Reference in New Issue
Block a user