Skip to content

Commit 12af1f2

Browse files
committed
[修改] 紀錄大平台的room_id
1 parent 7e0299d commit 12af1f2

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

backend/app/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,8 @@ def start_game(current_user, nickname):
208208
if current_user not in player_ids:
209209
return jsonify({"message": "Unauthorized to start this game"}), 403
210210

211-
room_id = GameService.create_game(player_ids, player_nickname)
212-
gameRoomID = str(room_id.game_id)
211+
game = GameService.create_game(player_ids, room_id, player_nickname)
212+
gameRoomID = str(game.game_id)
213213
return (
214214
jsonify(
215215
{

backend/domain/game.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class Game:
1717

1818
def __init__(self, game_id: str, players: List[dict], active: bool = True):
1919
self.game_id = game_id
20+
self.room_id:str = ""
2021
# 房間中的玩家
2122
self.players = [Player.from_dict(player) for player in players]
2223
self.active = active # 遊戲是否進行中
@@ -131,6 +132,7 @@ def to_dict(self) -> dict:
131132
"event_name": self.event_name,
132133
"spell_cast_number": self.spell_cast_number,
133134
"damage_info": self.damage_info,
135+
"room_id": self.room_id,
134136
}
135137

136138
if self.current_player is not None:
@@ -169,6 +171,9 @@ def from_dict(cls, data: dict) -> "Game":
169171
if "action_message" in data:
170172
game.action_message = data["action_message"]
171173

174+
if "room_id" in data:
175+
game.room_id = data["room_id"]
176+
172177
if "current_player" in data:
173178
game.current_player = data["current_player"]
174179

backend/service/game_service.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ def __init__(self, game_repository: GameRepository):
1010
self.game_repository = game_repository
1111

1212
def create_game(
13-
self, player_ids: list[str], player_nickname: Optional[List[str]] = None
13+
self, player_ids: list[str] ,room_id:Optional[str] = "" ,player_nickname: Optional[List[str]] = None
1414
) -> Game:
1515
game = Game(game_id=None, players=player_ids)
1616
game_id = self.game_repository.create_game(game)
17+
if room_id:
18+
game.room_id = room_id
1719
game.game_id = game_id # 從資料取得的game_id
1820
game.action_message = "開始遊戲"
1921
game.event_name = "game_started"

0 commit comments

Comments
 (0)