From 3d127482ca50d7a1ad155de380dc3a9dd1eb3c38 Mon Sep 17 00:00:00 2001 From: yock wang Date: Sat, 11 May 2024 17:34:04 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E6=96=B0=E5=A2=9E=20act?= =?UTF-8?q?ion=20message?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/service/game_service.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/backend/service/game_service.py b/backend/service/game_service.py index 0eb3f7a..9463609 100644 --- a/backend/service/game_service.py +++ b/backend/service/game_service.py @@ -37,8 +37,9 @@ def player_join_game(self, game_id: str, player_id: str) -> bool: if all_joined: game = self.start_game(game) + game.action_message = "回合開始" self.game_repository.update_game(game) - + return player_joined_stat def start_game(self, game: Game) -> Game: @@ -78,12 +79,12 @@ def cast_spell( player.prev_spell = spell_name if spell_name not in player.spells: # 施法失敗 + hp_damge = -1 if spell_name == "Magic 1": - # 喊出火龍,但手牌沒有火龍 - player.update_HP(roll_dice() * -1) - else: - player.update_HP(-1) - + # 喊得是火龍,玩家擲骰扣HP + hp_damge = roll_dice() * -1 + player.update_HP(hp_damge) + game.action_message = player.player_id + " 施放 " +spell_name + " 失敗自損 " + str(abs(hp_damge)) +" 滴血" self.game_repository.update_game(game) if player.get_HP() == 0: @@ -103,6 +104,7 @@ def cast_spell( # 玩家把手上所有的魔法石都用完了 if len(player.spells) == 0: # 儲存目前遊戲狀態 + game.action_message = player.player_id + " 手牌魔法石出完,局結束,結算分數" self.game_repository.update_game(game) # 結束這一局,結算分數 self.end_round(game_id, player_id) @@ -119,6 +121,7 @@ def cast_spell( # 將手牌放置於階梯 game.ladder.append(spell_name) # 儲存目前遊戲狀態 + game.action_message = player.player_id + " 施法 " + spell_name +" 成功 " self.game_repository.update_game(game) for p in game.players: @@ -167,7 +170,7 @@ def end_turn(self, game_id: str, player_id: str) -> bool: if game.warehouse: be_hand_stone = game.warehouse.pop() player.spells.append(be_hand_stone) - + game.action_message = player.player_id + " 回合結束" self.game_repository.update_game(game) return True @@ -196,7 +199,7 @@ def end_round(self, game_id: str, player_id: str) -> None: if len(p.secret_spells) > 0: # 持有秘密魔法石,有幾個加幾分 p.update_score(len(p.secret_spells)) - + game.action_message = "新局開始" self.game_repository.update_game(game) self.start_new_round(game_id) @@ -209,7 +212,7 @@ def start_new_round(self, game_id: str) -> None: game.turn = 1 game.shuffle_player() - + game.action_message = "回合開始" self.game_repository.update_game(game) for player in game.players: @@ -217,6 +220,7 @@ def start_new_round(self, game_id: str) -> None: # 已有玩家獲得8分 # 遊戲結束 game.active = False + game.action_message = "有玩家獲得8分,遊戲結束" self.game_repository.update_game(game) def player_status(self, game_id: str, player_id: str):