Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -90,9 +90,6 @@ async def handle_action(request: Request):
|
|
| 90 |
|
| 91 |
game = games[pin]
|
| 92 |
|
| 93 |
-
if action == 'getStatus':
|
| 94 |
-
return {"success": True, "challenge": game.get("challenge", None)}
|
| 95 |
-
|
| 96 |
if action == 'steal':
|
| 97 |
game["challenge"] = {
|
| 98 |
"action": 'steal',
|
|
@@ -116,19 +113,24 @@ async def handle_action(request: Request):
|
|
| 116 |
challenger["coins"] += coins_to_steal
|
| 117 |
game["challenge"] = None
|
| 118 |
return {"success": True, "message": f"Steal accepted. {coins_to_steal} coins transferred from {target_player['name']} to {challenger['name']}."}
|
|
|
|
| 119 |
elif response == 'challenge':
|
| 120 |
if "Captain" in challenger["cards"]:
|
| 121 |
coins_to_steal = min(target_player["coins"], 2)
|
| 122 |
target_player["coins"] -= coins_to_steal
|
| 123 |
challenger["coins"] += coins_to_steal
|
| 124 |
-
game["challenge"] =
|
| 125 |
-
return {"success": True, "message": f"Challenge failed. {target_player['name']} loses {coins_to_steal} coins to {challenger['name']}."}
|
| 126 |
else:
|
| 127 |
game["challenge"]["status"] = 'choose'
|
| 128 |
return {"success": True, "message": f"Challenge successful. {challenger['name']} must choose a card to lose.", "challenge": game["challenge"]}
|
| 129 |
|
| 130 |
if action == 'choose':
|
| 131 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
if target in challenger["cards"]:
|
| 133 |
challenger["cards"].remove(target)
|
| 134 |
game["challenge"] = None
|
|
|
|
| 90 |
|
| 91 |
game = games[pin]
|
| 92 |
|
|
|
|
|
|
|
|
|
|
| 93 |
if action == 'steal':
|
| 94 |
game["challenge"] = {
|
| 95 |
"action": 'steal',
|
|
|
|
| 113 |
challenger["coins"] += coins_to_steal
|
| 114 |
game["challenge"] = None
|
| 115 |
return {"success": True, "message": f"Steal accepted. {coins_to_steal} coins transferred from {target_player['name']} to {challenger['name']}."}
|
| 116 |
+
|
| 117 |
elif response == 'challenge':
|
| 118 |
if "Captain" in challenger["cards"]:
|
| 119 |
coins_to_steal = min(target_player["coins"], 2)
|
| 120 |
target_player["coins"] -= coins_to_steal
|
| 121 |
challenger["coins"] += coins_to_steal
|
| 122 |
+
game["challenge"]["status"] = 'chooseChallenger'
|
| 123 |
+
return {"success": True, "message": f"Challenge failed. {target_player['name']} loses {coins_to_steal} coins to {challenger['name']}. The challenger must now choose a card to lose.", "challenge": game["challenge"]}
|
| 124 |
else:
|
| 125 |
game["challenge"]["status"] = 'choose'
|
| 126 |
return {"success": True, "message": f"Challenge successful. {challenger['name']} must choose a card to lose.", "challenge": game["challenge"]}
|
| 127 |
|
| 128 |
if action == 'choose':
|
| 129 |
+
if game["challenge"]["status"] == 'choose':
|
| 130 |
+
challenger = next(p for p in game["players"] if p["name"] == game["challenge"]["challenger"])
|
| 131 |
+
elif game["challenge"]["status"] == 'chooseChallenger':
|
| 132 |
+
challenger = next(p for p in game["players"] if p["name"] == game["challenge"]["target"])
|
| 133 |
+
|
| 134 |
if target in challenger["cards"]:
|
| 135 |
challenger["cards"].remove(target)
|
| 136 |
game["challenge"] = None
|