Update templates
Browse files
templates
CHANGED
|
@@ -1,45 +1,66 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from flask import Flask, render_template, request, jsonify
|
| 2 |
+
from flask_socketio import SocketIO, emit
|
| 3 |
+
import random
|
| 4 |
+
|
| 5 |
+
app = Flask(__name__)
|
| 6 |
+
# WICHTIG: cors_allowed_origins="*" erlaubt deiner Webseite den Zugriff auf HF
|
| 7 |
+
socketio = SocketIO(app, cors_allowed_origins="*", async_mode='eventlet')
|
| 8 |
+
|
| 9 |
+
players = {}
|
| 10 |
+
game_state = {
|
| 11 |
+
"racing": False,
|
| 12 |
+
"pott": 0,
|
| 13 |
+
"current_bet": 50,
|
| 14 |
+
"horses": [
|
| 15 |
+
{"id": 0, "name": "Gelb", "pos": 0, "color": "#FFD700"},
|
| 16 |
+
{"id": 1, "name": "Grün", "pos": 0, "color": "#32CD32"},
|
| 17 |
+
{"id": 2, "name": "Silber", "pos": 0, "color": "#C0C0C0"},
|
| 18 |
+
{"id": 3, "name": "Rot", "pos": 0, "color": "#DC143C"}
|
| 19 |
+
]
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
@app.route('/')
|
| 23 |
+
def index():
|
| 24 |
+
return render_template('index.html')
|
| 25 |
+
|
| 26 |
+
@app.route('/login', methods=['POST'])
|
| 27 |
+
def login():
|
| 28 |
+
data = request.json
|
| 29 |
+
email = data.get('email')
|
| 30 |
+
if email not in players:
|
| 31 |
+
players[email] = {"email": email, "coins": 1000, "bet_on": None}
|
| 32 |
+
return jsonify({"stats": players[email]})
|
| 33 |
+
|
| 34 |
+
@socketio.on('join_game')
|
| 35 |
+
def join(data):
|
| 36 |
+
emit('update_table', {"game": game_state, "players": list(players.values())}, broadcast=True)
|
| 37 |
+
|
| 38 |
+
@socketio.on('place_bet')
|
| 39 |
+
def place_bet(data):
|
| 40 |
+
email = data.get('email')
|
| 41 |
+
h_id = int(data.get('horse_id'))
|
| 42 |
+
if email in players and not game_state["racing"]:
|
| 43 |
+
players[email]["bet_on"] = h_id
|
| 44 |
+
game_state["pott"] += game_state["current_bet"]
|
| 45 |
+
players[email]["coins"] -= game_state["current_bet"]
|
| 46 |
+
emit('update_table', {"game": game_state, "players": list(players.values())}, broadcast=True)
|
| 47 |
+
|
| 48 |
+
@socketio.on('start_round') # Oder über Admin-Button
|
| 49 |
+
def start_race(data):
|
| 50 |
+
if game_state["racing"]: return
|
| 51 |
+
game_state["racing"] = True
|
| 52 |
+
winner = None
|
| 53 |
+
while not winner:
|
| 54 |
+
for h in game_state["horses"]:
|
| 55 |
+
h["pos"] += random.uniform(1, 5)
|
| 56 |
+
if h["pos"] >= 100: winner = h
|
| 57 |
+
socketio.emit('race_progress', {"horses": game_state["horses"]})
|
| 58 |
+
socketio.sleep(0.1)
|
| 59 |
+
|
| 60 |
+
socketio.emit('race_over', {"winner": winner["name"]})
|
| 61 |
+
# Reset Logik hier...
|
| 62 |
+
game_state["racing"] = False
|
| 63 |
+
|
| 64 |
+
if __name__ == '__main__':
|
| 65 |
+
# Port 7860 ist für HF zwingend!
|
| 66 |
+
socketio.run(app, host='0.0.0.0', port=7860)
|