4ff62e29bd
- 创建 idioms 表(102条谜语式成语题库)和 idiom_game_rounds 表 - 后台成语管理页面:增删改题目 + 游戏参数(金币/经验/间隔)内联设置 + 出题按钮 - IdiomQuizController:出题/答题/当前回合查询,Redis 防并发抢答 - IdiomGameStarted / IdiomGameAnswered 广播事件 - 前端答题弹窗模块:聊天消息带【答题】按钮,点击弹出输入框 - GameConfig 注册 idiom 游戏,由 admin.game-configs 统一管理开关
64 lines
1.6 KiB
PHP
64 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 IdiomGameStarted implements ShouldBroadcastNow
|
|
{
|
|
use Dispatchable, InteractsWithSockets, SerializesModels;
|
|
|
|
/**
|
|
* @param int $roomId 房间 ID
|
|
* @param string $hint 谜语提示
|
|
* @param int $roundId 游戏回合 ID(前端提交答案时带上)
|
|
* @param int $rewardGold 答对奖励金币
|
|
* @param int $rewardExp 答对奖励经验
|
|
*/
|
|
public function __construct(
|
|
public readonly int $roomId,
|
|
public readonly string $hint,
|
|
public readonly int $roundId,
|
|
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,
|
|
'hint' => $this->hint,
|
|
'reward_gold' => $this->rewardGold,
|
|
'reward_exp' => $this->rewardExp,
|
|
'message' => "🧩 猜成语时间!{$this->hint}",
|
|
];
|
|
}
|
|
}
|