boardgame-phaser/QWEN.md

55 lines
1.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# boardgame-phaser
基于Phaser3/boardgame-core的游戏框架
## 概述
项目使用pnpm monorepo管理包含以下包
- `framework`:通用框架
- `boop-game`boop样例
- `sample-game`tic tac toe样例
游戏应当使用vite构建基于`preact/signals`进行状态管理,使用`phaser3`实现游戏功能。
## boardgame-core
项目使用`boardgame-core`进行游戏定义。
`boardgame-core`的内容可以在`framework/node_modules/boardgame-core`找到。
这个文件夹被.gitignore忽略查看时需要绕开这一限制。
## 编写游戏
游戏逻辑以gameModule的形式定义
```typescript
import {createGameCommandRegistry, IGameContext} from "boardgame-core";
// 创建mutative游戏初始状态
export function createInitialState(): GameState {
//...
}
// 运行游戏
export async function start(game: IGameContext<GameState>) {
// ...
}
// 可选
export const registry = createGameCommandRegistry();
```
使用以下步骤创建游戏:
### 1. 定义状态
游戏状态使用一个大的`mutative`对象来描述,所有的状态更新通过`game.produce`或`game.produceAsync`来实现。
通常使用一个`regions: Record<string, Region>`和一个`parts: Record<string, Part<TMeta>>`来记录桌游物件的摆放。
### 2. 定义流程
使用`async function start(game: IGameContext<GameState>)`作为入口。
需要等待玩家交互时,使用`await game.prompt(schema, validator, player)`。