Spaces:
Sleeping
Sleeping
Create games.py
Browse files- app/games.py +38 -0
app/games.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
def start_game(data):
|
3 |
+
"""Startet ein neues Spiel"""
|
4 |
+
logger.info("Starting a new game...")
|
5 |
+
return jsonify({
|
6 |
+
"type": 4,
|
7 |
+
"data": {
|
8 |
+
"content": "🎮 Ein neues Spiel wurde gestartet!"
|
9 |
+
}
|
10 |
+
})
|
11 |
+
# d) /fish (Fischen)
|
12 |
+
def fish_command(user_id, location):
|
13 |
+
"""Fishing game where user can fish at different locations"""
|
14 |
+
user_data = get_user_data(user_id)
|
15 |
+
if user_data['credits'] < 10: # Fischen kostet 10 Credits
|
16 |
+
return jsonify({"type": 4, "data": {"content": "Nicht genug Credits zum Fischen!"}})
|
17 |
+
|
18 |
+
if location == "river":
|
19 |
+
chance = random.randint(1, 100)
|
20 |
+
if chance <= 70: # 70% Chance auf einen kleinen Fisch
|
21 |
+
reward = 20 # Der Benutzer verdient 20 Credits
|
22 |
+
else:
|
23 |
+
reward = -10 # 30% Chance auf einen Unfall
|
24 |
+
elif location == "lake":
|
25 |
+
chance = random.randint(1, 100)
|
26 |
+
if chance <= 50: # 50% Chance auf einen großen Fisch
|
27 |
+
reward = 50 # Der Benutzer verdient 50 Credits
|
28 |
+
else:
|
29 |
+
reward = -30 # 50% Chance auf einen Unfall
|
30 |
+
|
31 |
+
# Fische und aktualisiere die Credits
|
32 |
+
new_credits = user_data.get('credits', 0) + reward
|
33 |
+
update_user_data(user_id, {'credits': new_credits})
|
34 |
+
|
35 |
+
return jsonify({
|
36 |
+
"type": 4,
|
37 |
+
"data": {"content": f"Du hast {reward} Credits gefangen!" if reward >= 0 else f"Du hast {abs(reward)} Credits verloren!"}
|
38 |
+
})
|