incognitolm commited on
Commit
57c27f4
·
verified ·
1 Parent(s): 01ae357

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -12
app.py CHANGED
@@ -37,7 +37,7 @@ async def create_game(request: Request):
37
  "currentChallenge": None,
38
  "pendingCardLoss": None,
39
  "votes": [],
40
- "permissions": {player_name: True} # default permission True for the creator
41
  }
42
 
43
  return {"success": True, "message": "Game created successfully!"}
@@ -94,14 +94,16 @@ async def handle_action(request: Request):
94
  return {"success": True, "challenge": game.get("challenge", None)}
95
 
96
  if action == 'steal':
97
- game["challenge"] = {
98
- "action": 'steal',
99
- "challenger": player,
100
- "target": target,
101
- "challengeType": 'steal',
102
- "status": 'pending'
103
- }
104
- return {"success": True, "message": f"Steal initiated by {player} targeting {target}. Awaiting response from {target}."}
 
 
105
 
106
  if action == 'challengeResponse':
107
  if not game.get("challenge"):
@@ -144,10 +146,10 @@ async def handle_action(request: Request):
144
  for p in game["players"]:
145
  if p["name"] == player:
146
  player_found = True
147
- if not game["permissions"].get(player, False):
148
  raise HTTPException(status_code=403, detail="You already took coins, and cannot take income.")
149
  p["coins"] += 1
150
- game["permissions"][player] = False # set permission to false after taking income
151
  return {"success": True, "message": f"Player {player} now has {p['coins']} coins."}
152
  if not player_found:
153
  raise HTTPException(status_code=404, detail="Player not found in the game.")
@@ -166,7 +168,8 @@ async def join_game(request: Request):
166
 
167
  game["players"].append(player_name)
168
  # Add the new player's permission as True in the dictionary
169
- game["permissions"][player_name] = True
 
170
  return {"success": True, "message": "Player joined successfully!"}
171
 
172
  @app.put("/api/startGame")
 
37
  "currentChallenge": None,
38
  "pendingCardLoss": None,
39
  "votes": [],
40
+ "permissions": {player_name: {"steal": True, "gain": True}
41
  }
42
 
43
  return {"success": True, "message": "Game created successfully!"}
 
94
  return {"success": True, "challenge": game.get("challenge", None)}
95
 
96
  if action == 'steal':
97
+ if game["permissions"].get(player, {}).get("steal", True):
98
+ game["challenge"] = {
99
+ "action": 'steal',
100
+ "challenger": player,
101
+ "target": target,
102
+ "challengeType": 'steal',
103
+ "status": 'pending'
104
+ }
105
+ game["permissions"][player]["steal"] = False
106
+ return {"success": True, "message": f"Steal initiated by {player} targeting {target}. Awaiting response from {target}."}
107
 
108
  if action == 'challengeResponse':
109
  if not game.get("challenge"):
 
146
  for p in game["players"]:
147
  if p["name"] == player:
148
  player_found = True
149
+ if game["permissions"].get(player, {}).get("gain", True):
150
  raise HTTPException(status_code=403, detail="You already took coins, and cannot take income.")
151
  p["coins"] += 1
152
+ game["permissions"][player]["gain"] = False
153
  return {"success": True, "message": f"Player {player} now has {p['coins']} coins."}
154
  if not player_found:
155
  raise HTTPException(status_code=404, detail="Player not found in the game.")
 
168
 
169
  game["players"].append(player_name)
170
  # Add the new player's permission as True in the dictionary
171
+ game["permissions"][player_name]["steal"] = True
172
+ game["permissions"][player_name]["gain"] = True
173
  return {"success": True, "message": "Player joined successfully!"}
174
 
175
  @app.put("/api/startGame")