feat(游戏模块): 重构比赛逻辑并添加赛制支持
- 移除了原有的比赛时间检查逻辑 - 引入了赛制类文件,实现了比赛自动编排功能 - 新增了 GameMatch 模型用于存储比赛对阵信息 - 优化了数据库事务处理逻辑 - 更新了 Composer 自动加载配置,添加 format 命名空间
This commit is contained in:
72
format/Game17.php
Normal file
72
format/Game17.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace format;
|
||||
|
||||
class Game17 implements GameInterface
|
||||
{
|
||||
// 赛制说明
|
||||
public function describe(): string
|
||||
{
|
||||
return '双打+八人转 比赛说明:
|
||||
每个人与其他人各搭档1次,决出个人排名
|
||||
数 4 ≦ n ≦ 16 (Default:8)
|
||||
轮数 3 ≦ m<n (Default:7)
|
||||
报名费 0 ≦ m ≦ 10 元 (Default: 5)
|
||||
由前几名按比例瓜分 (可调 Default:40%/30%/20%/10%)';
|
||||
}
|
||||
|
||||
// 对阵安排
|
||||
public function match($game, $users): array
|
||||
{
|
||||
$math = $team = [];
|
||||
$utotal = count($users);
|
||||
for ($i = 0; $i < $utotal; $i++) {
|
||||
for ($j = $i + 1; $j < $utotal; $j++) {
|
||||
$team[] = json_encode([
|
||||
'name' => 'team' . $i . $j,
|
||||
'user' => [
|
||||
[
|
||||
'user_id' => $users[$i]['user_id'],
|
||||
'gender' => $users[$i]['gender'],
|
||||
'avatar' => $users[$i]['avatar'],
|
||||
'name' => $users[$i]['name'],
|
||||
],
|
||||
[
|
||||
'user_id' => $users[$j]['user_id'],
|
||||
'gender' => $users[$j]['gender'],
|
||||
'avatar' => $users[$j]['avatar'],
|
||||
'name' => $users[$j]['name'],
|
||||
]
|
||||
]
|
||||
]);
|
||||
}
|
||||
}
|
||||
// dd($team);
|
||||
$ttotal = count($users);
|
||||
$n = 1;
|
||||
for ($i = 0; $i < $ttotal; $i++) {
|
||||
for ($j = $i + 1; $j < $ttotal; $j++) {
|
||||
$math[] = [
|
||||
'gym_id' => $game['gym_id'],
|
||||
'club_id' => $game['club_id'],
|
||||
'act_id' => $game['act_id'],
|
||||
'game_id' => $game['id'],
|
||||
'level' => 1,
|
||||
'turn' => $n,
|
||||
'teamA' => $team[$i],
|
||||
'teamB' => $team[$j],
|
||||
];
|
||||
$n++;
|
||||
}
|
||||
}
|
||||
// dd($math);
|
||||
|
||||
return $math;
|
||||
}
|
||||
|
||||
// 奖金分配
|
||||
public function prize($rank): array
|
||||
{
|
||||
return $rank;
|
||||
}
|
||||
}
|
||||
24
format/GameInterface.php
Normal file
24
format/GameInterface.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace format;
|
||||
/*
|
||||
赛制文件
|
||||
|
||||
1. 团队类型:1双打,2单打,3团队
|
||||
2. 规则类型:1八人转,2超八转,3混双转,4固搭转,5固定擂,6活动擂,7转转,8分区转,9擂台赛,10守擂赛,11追分赛,12固搭追分赛,13大循环群内赛,14两队PK赛,15战队淘汰赛,16单项淘汰赛,17分区循环淘汰赛
|
||||
|
||||
3. 需要引入新赛制请创建新的类文件,类文件需要实现GameInterface接口,并且文件名为`Game + 团队类型代码 + 规则类型代码.php`。
|
||||
如:赛制为双打八人转,则文件为format/Game11.php。
|
||||
赛制为单打擂台赛,则文件为format/Game29.php。
|
||||
*/
|
||||
interface GameInterface
|
||||
{
|
||||
// 赛制说明
|
||||
public function describe(): string;
|
||||
|
||||
// 对阵安排
|
||||
public function match($game,$users): array;
|
||||
|
||||
// 奖金分配
|
||||
public function prize($rank): array;
|
||||
}
|
||||
Reference in New Issue
Block a user