init
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import eventlet
|
||||
|
||||
eventlet.monkey_patch()
|
||||
|
||||
from flask import Flask, jsonify
|
||||
from flask_cors import CORS
|
||||
from flask_socketio import SocketIO
|
||||
|
||||
app = Flask(__name__)
|
||||
CORS(app, origins=["http://localhost:3000"])
|
||||
socketio = SocketIO(app, cors_allowed_origins="*")
|
||||
|
||||
|
||||
game_state = {
|
||||
"gameActive": True,
|
||||
"players": ["Alice", "Bob", "Charlie"],
|
||||
"playerTurn": 0
|
||||
}
|
||||
|
||||
@app.route("/status", methods=["GET"])
|
||||
def status():
|
||||
return jsonify(game_state)
|
||||
|
||||
@app.route("/next", methods=["GET"])
|
||||
def next_player():
|
||||
players = game_state["players"]
|
||||
if not players:
|
||||
return jsonify({"error": "No players"}), 400
|
||||
|
||||
current_player = players[game_state["playerTurn"]]
|
||||
|
||||
# Advance the turn
|
||||
game_state["playerTurn"] = (game_state["playerTurn"] + 1) % len(players)
|
||||
|
||||
socketio.emit("player_update", {"nextPlayer": current_player}) # Tell clients listening of update
|
||||
return jsonify({
|
||||
"nextPlayer": current_player
|
||||
})
|
||||
|
||||
if __name__ == "__main__":
|
||||
socketio.run(app, host="localhost", port=8080)
|
||||
Reference in New Issue
Block a user