feat: 猜成语游戏 - 完整题库、管理后台、答题弹窗
- 创建 idioms 表(102条谜语式成语题库)和 idiom_game_rounds 表 - 后台成语管理页面:增删改题目 + 游戏参数(金币/经验/间隔)内联设置 + 出题按钮 - IdiomQuizController:出题/答题/当前回合查询,Redis 防并发抢答 - IdiomGameStarted / IdiomGameAnswered 广播事件 - 前端答题弹窗模块:聊天消息带【答题】按钮,点击弹出输入框 - GameConfig 注册 idiom 游戏,由 admin.game-configs 统一管理开关
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:创建猜成语题库表
|
||||
*
|
||||
* 存储成语题目及答案,管理员可在后台增删改。
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* 创建 idioms 表。
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('idioms', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('answer', 50)->comment('成语答案');
|
||||
$table->string('hint', 255)->comment('谜语线索提示');
|
||||
$table->boolean('is_active')->default(true)->comment('是否启用');
|
||||
$table->unsignedSmallInteger('sort')->default(0)->comment('排序');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 回滚迁移。
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('idioms');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:创建猜成语游戏回合表
|
||||
*
|
||||
* 每次出题对应一个回合,记录答题状态、奖励和获胜者。
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* 创建 idiom_game_rounds 表。
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('idiom_game_rounds', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('room_id')->comment('游戏所在房间 ID');
|
||||
$table->unsignedBigInteger('idiom_id')->comment('当前题目 ID');
|
||||
$table->string('status', 20)->default('pending')->comment('状态:pending/active/answered/ended');
|
||||
$table->integer('reward_gold')->default(0)->comment('答对奖励金币');
|
||||
$table->integer('reward_exp')->default(0)->comment('答对奖励经验');
|
||||
$table->unsignedBigInteger('winner_id')->nullable()->comment('答对用户 ID');
|
||||
$table->string('winner_username', 50)->nullable()->comment('答对用户名');
|
||||
$table->timestamp('started_at')->nullable()->comment('开始答题时间');
|
||||
$table->timestamp('ended_at')->nullable()->comment('结束答题时间');
|
||||
$table->timestamps();
|
||||
|
||||
$table->foreign('idiom_id')->references('id')->on('idioms')->onDelete('cascade');
|
||||
$table->index('status');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 回滚迁移。
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('idiom_game_rounds');
|
||||
}
|
||||
};
|
||||
@@ -169,6 +169,20 @@ class GameConfigSeeder extends Seeder
|
||||
'super_issue_inject' => 20000, // 超级期系统注入金额上限
|
||||
],
|
||||
],
|
||||
|
||||
// ─── 猜成语 ───────────────────────────────────────────────
|
||||
[
|
||||
'game_key' => 'idiom',
|
||||
'name' => '猜成语',
|
||||
'icon' => '🧩',
|
||||
'description' => '管理员手动出题或系统定时自动出题,用户抢答成语,第一个答对的获得金币和经验奖励。',
|
||||
'enabled' => false,
|
||||
'params' => [
|
||||
'reward_gold' => 50, // 答对奖励金币
|
||||
'reward_exp' => 30, // 答对奖励经验
|
||||
'auto_start_interval' => 0, // 自动出题间隔(分钟,0=手动)
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($games as $game) {
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 猜成语题库导入脚本
|
||||
* 从 storage/data/idioms.php 导入初始数据
|
||||
*/
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Idiom;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class IdiomSeeder extends Seeder
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
$idioms = require storage_path('data/idioms.php');
|
||||
|
||||
foreach ($idioms as $i => $item) {
|
||||
Idiom::create([
|
||||
'answer' => $item['answer'],
|
||||
'hint' => $item['hint'],
|
||||
'is_active' => true,
|
||||
'sort' => $i,
|
||||
]);
|
||||
}
|
||||
|
||||
$this->command->info('已导入 '.count($idioms).' 条成语题目。');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user