incognitolm commited on
Commit
5b93212
·
verified ·
1 Parent(s): bee68c8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -3
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}
41
  }
42
 
43
  return {"success": True, "message": "Game created successfully!"}
@@ -137,7 +137,17 @@ async def handle_action(request: Request):
137
  return {"success": False, "message": f"Card {target} not found in {challenger['name']}'s hand."}
138
 
139
  if action == 'income':
140
- player["coins"] += 1
 
 
 
 
 
 
 
 
 
 
141
 
142
  return {"success": True, "message": f"Action '{action}' processed for player {player}."}
143
 
@@ -152,7 +162,8 @@ async def join_game(request: Request):
152
  raise HTTPException(status_code=404, detail="Game not found.")
153
 
154
  game["players"].append(player_name)
155
- game["permissions"][player_name] = True
 
156
  return {"success": True, "message": "Player joined successfully!"}
157
 
158
  @app.put("/api/startGame")
 
37
  "currentChallenge": None,
38
  "pendingCardLoss": None,
39
  "votes": [],
40
+ "permissions": {player_name: 1} # using a dictionary for permissions
41
  }
42
 
43
  return {"success": True, "message": "Game created successfully!"}
 
137
  return {"success": False, "message": f"Card {target} not found in {challenger['name']}'s hand."}
138
 
139
  if action == 'income':
140
+ # Find the player's dictionary and update coins if game has started
141
+ player_found = False
142
+ for p in game["players"]:
143
+ if p["name"] == player:
144
+ p["coins"] += 1
145
+ player_found = True
146
+ permissions[player] = False
147
+ break
148
+ if not player_found:
149
+ raise HTTPException(status_code=404, detail="Player not found in the game.")
150
+ return {"success": True, "message": f"Player {player} now has {p['coins']} coins."}
151
 
152
  return {"success": True, "message": f"Action '{action}' processed for player {player}."}
153
 
 
162
  raise HTTPException(status_code=404, detail="Game not found.")
163
 
164
  game["players"].append(player_name)
165
+ # Add the new player's permission as 1 in the dictionary
166
+ game["permissions"][player_name] = 1
167
  return {"success": True, "message": "Player joined successfully!"}
168
 
169
  @app.put("/api/startGame")