Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -37,7 +37,7 @@ async def create_game(request: Request):
|
|
| 37 |
"currentChallenge": None,
|
| 38 |
"pendingCardLoss": None,
|
| 39 |
"votes": [],
|
| 40 |
-
"permissions":
|
| 41 |
}
|
| 42 |
|
| 43 |
return {"success": True, "message": "Game created successfully!"}
|
|
@@ -47,7 +47,7 @@ async def test():
|
|
| 47 |
return {"success": True}
|
| 48 |
|
| 49 |
@app.get("/api/getGames")
|
| 50 |
-
async def getGames():
|
| 51 |
return {"success": True, "data": games}
|
| 52 |
|
| 53 |
@app.get("/api/gameData")
|
|
@@ -138,8 +138,7 @@ async def handle_action(request: Request):
|
|
| 138 |
|
| 139 |
if action == 'income':
|
| 140 |
player["coins"] += 1
|
| 141 |
-
|
| 142 |
-
|
| 143 |
return {"success": True, "message": f"Action '{action}' processed for player {player}."}
|
| 144 |
|
| 145 |
@app.post("/api/joinGame")
|
|
@@ -153,7 +152,8 @@ async def join_game(request: Request):
|
|
| 153 |
raise HTTPException(status_code=404, detail="Game not found.")
|
| 154 |
|
| 155 |
game["players"].append(player_name)
|
| 156 |
-
|
|
|
|
| 157 |
return {"success": True, "message": "Player joined successfully!"}
|
| 158 |
|
| 159 |
@app.put("/api/startGame")
|
|
@@ -179,5 +179,8 @@ async def start_game(request: Request):
|
|
| 179 |
|
| 180 |
def generate_cards():
|
| 181 |
cards = ['Duke', 'Assassin', 'Captain', 'Ambassador', 'Contessa']
|
| 182 |
-
shuffled = sorted(cards, key=lambda x: 0.5 - random.random())
|
| 183 |
-
return [shuffled[0], shuffled[1]]
|
|
|
|
|
|
|
|
|
|
|
|
| 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!"}
|
|
|
|
| 47 |
return {"success": True}
|
| 48 |
|
| 49 |
@app.get("/api/getGames")
|
| 50 |
+
async def getGames():
|
| 51 |
return {"success": True, "data": games}
|
| 52 |
|
| 53 |
@app.get("/api/gameData")
|
|
|
|
| 138 |
|
| 139 |
if action == 'income':
|
| 140 |
player["coins"] += 1
|
| 141 |
+
|
|
|
|
| 142 |
return {"success": True, "message": f"Action '{action}' processed for player {player}."}
|
| 143 |
|
| 144 |
@app.post("/api/joinGame")
|
|
|
|
| 152 |
raise HTTPException(status_code=404, detail="Game not found.")
|
| 153 |
|
| 154 |
game["players"].append(player_name)
|
| 155 |
+
# Add the new player's permission as 1 in the dictionary
|
| 156 |
+
game["permissions"][player_name] = 1
|
| 157 |
return {"success": True, "message": "Player joined successfully!"}
|
| 158 |
|
| 159 |
@app.put("/api/startGame")
|
|
|
|
| 179 |
|
| 180 |
def generate_cards():
|
| 181 |
cards = ['Duke', 'Assassin', 'Captain', 'Ambassador', 'Contessa']
|
| 182 |
+
shuffled = sorted(cards, key=lambda x: 0.5 - random.random())
|
| 183 |
+
return [shuffled[0], shuffled[1]]
|
| 184 |
+
|
| 185 |
+
if __name__ == "__main__":
|
| 186 |
+
uvicorn.run(app, host="0.0.0.0", port=8000)
|