五子棋:AI 获胜(玩家输局)时也向聊天室发送系统广播通知
This commit is contained in:
@@ -456,10 +456,22 @@ class GomokuController extends Controller
|
||||
// 广播对局结束事件给参与对局的双方
|
||||
broadcast(new GomokuFinishedEvent($game->fresh(), $winnerName, $loserName, $reason));
|
||||
|
||||
// 有胜负,并且非 AI 获胜,发送系统房间广播
|
||||
if ($winnerColor !== 0 && $winnerName && $winnerName !== "AI(难度{$game->ai_level})") {
|
||||
$msgType = $game->mode === 'pvp' ? '玩家对战' : "人机对战(难度{$game->ai_level})";
|
||||
$text = "🎉 棋神降临!恭喜玩家【{$winnerName}】在五子棋{$msgType}中击败了【{$loserName}】,赢得了 {$rewardGold} 金币奖励!";
|
||||
// 有胜负,均向房间广播系统通知
|
||||
if ($winnerColor !== 0) {
|
||||
if ($game->mode === 'pvp') {
|
||||
// PvP:胜方玩家获奖通知
|
||||
$reasonText = match ($reason) {
|
||||
'resign' => '(认输)',
|
||||
default => '',
|
||||
};
|
||||
$text = "🎉 棋神降临!恭喜玩家【{$winnerName}】在五子棋玩家对战中击败了【{$loserName}】{$reasonText},赢得了 {$rewardGold} 金币奖励!";
|
||||
} elseif ($winnerColor === 1) {
|
||||
// PvE:玩家获胜
|
||||
$text = "🎉 棋神降临!恭喜玩家【{$winnerName}】在五子棋人机对战(难度{$game->ai_level})中击败了【{$loserName}】,赢得了 {$rewardGold} 金币奖励!";
|
||||
} else {
|
||||
// PvE:AI 获胜(玩家输了)
|
||||
$text = "🤖 AI 大获全胜!玩家【{$loserName}】在五子棋人机对战(难度{$game->ai_level})中不敌 AI,再接再厉!";
|
||||
}
|
||||
$this->broadcastSystemMessage($game->room_id, $text);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user