4ff62e29bd
- 创建 idioms 表(102条谜语式成语题库)和 idiom_game_rounds 表 - 后台成语管理页面:增删改题目 + 游戏参数(金币/经验/间隔)内联设置 + 出题按钮 - IdiomQuizController:出题/答题/当前回合查询,Redis 防并发抢答 - IdiomGameStarted / IdiomGameAnswered 广播事件 - 前端答题弹窗模块:聊天消息带【答题】按钮,点击弹出输入框 - GameConfig 注册 idiom 游戏,由 admin.game-configs 统一管理开关
60 lines
1.6 KiB
PHP
60 lines
1.6 KiB
PHP
<?php
|
|
|
|
/**
|
|
* 文件功能:猜成语答题结果广播事件
|
|
*
|
|
* 用户答对成语时广播,通知房间内所有用户结果。
|
|
*
|
|
* @author ChatRoom Laravel
|
|
*
|
|
* @version 1.0.0
|
|
*/
|
|
|
|
namespace App\Events;
|
|
|
|
use Illuminate\Broadcasting\InteractsWithSockets;
|
|
use Illuminate\Broadcasting\PresenceChannel;
|
|
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
|
|
use Illuminate\Foundation\Events\Dispatchable;
|
|
use Illuminate\Queue\SerializesModels;
|
|
|
|
class IdiomGameAnswered implements ShouldBroadcastNow
|
|
{
|
|
use Dispatchable, InteractsWithSockets, SerializesModels;
|
|
|
|
/**
|
|
* @param int $roomId 房间 ID
|
|
* @param int $roundId 游戏回合 ID
|
|
* @param string $answer 正确答案
|
|
* @param string $winnerUsername 答对的用户名
|
|
* @param int $rewardGold 获得的金币
|
|
* @param int $rewardExp 获得的经验
|
|
*/
|
|
public function __construct(
|
|
public readonly int $roomId,
|
|
public readonly int $roundId,
|
|
public readonly string $answer,
|
|
public readonly string $winnerUsername,
|
|
public readonly int $rewardGold = 0,
|
|
public readonly int $rewardExp = 0,
|
|
) {}
|
|
|
|
public function broadcastOn(): array
|
|
{
|
|
return [
|
|
new PresenceChannel('room.'.$this->roomId),
|
|
];
|
|
}
|
|
|
|
public function broadcastWith(): array
|
|
{
|
|
return [
|
|
'round_id' => $this->roundId,
|
|
'answer' => $this->answer,
|
|
'winner_username' => $this->winnerUsername,
|
|
'reward_gold' => $this->rewardGold,
|
|
'reward_exp' => $this->rewardExp,
|
|
];
|
|
}
|
|
}
|