feat: 重构游戏房间架构
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
package com.webgame.webgamebackend.config;
|
||||
|
||||
import com.webgame.webgamebackend.repository.GameMoveRepository;
|
||||
import com.webgame.webgamebackend.service.engine.GameEngineRegistry;
|
||||
import com.webgame.webgamebackend.service.engine.GomokuEngine;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* 游戏引擎注册配置
|
||||
*
|
||||
* 在 Spring 启动后,将所有已实现的 GameEngine 注册到 GameEngineRegistry。
|
||||
* 新增游戏只需在此处添加一行注册即可。
|
||||
*/
|
||||
@Slf4j
|
||||
@Configuration
|
||||
@RequiredArgsConstructor
|
||||
public class EngineRegistrationConfig {
|
||||
|
||||
private final GameEngineRegistry registry;
|
||||
private final GameMoveRepository moveRepository;
|
||||
|
||||
@PostConstruct
|
||||
public void registerEngines() {
|
||||
// 注册五子棋引擎
|
||||
registry.register("gomoku", context -> new GomokuEngine(moveRepository));
|
||||
log.info("[引擎注册] 已注册五子棋引擎, gameId=gomoku");
|
||||
|
||||
// TODO: 后续新游戏在此注册,例如:
|
||||
// registry.register("snake", context -> new SnakeEngine(...));
|
||||
// registry.register("tetris", context -> new TetrisEngine(...));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user