Documentation
¶
Index ¶
- type ActionType
- type Camp
- type Config
- type Engine
- func (e *Engine) AddPlayer(playerID string) error
- func (e *Engine) AdvancePhase(nextPhase PhaseType) error
- func (e *Engine) CheckWinCondition() Camp
- func (e *Engine) EndGame(winner Camp)
- func (e *Engine) GetPlayerState(playerID string) (PlayerState, error)
- func (e *Engine) GetState() GameState
- func (e *Engine) KillPlayer(playerID string, reason string) error
- func (e *Engine) PerformAction(playerID string, actionType ActionType, targetID string, ...) error
- func (e *Engine) Start() error
- func (e *Engine) Subscribe(eventType EventType, handler EventHandler) SubscriptionID
- func (e *Engine) Unsubscribe(id SubscriptionID)
- type Event
- type EventHandler
- type EventType
- type GameState
- type PhaseType
- type PlayerState
- type Role
- type RoleType
- type Skill
- type SkillType
- type SubscriptionID
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ActionType ¶
type ActionType string
ActionType 玩家行动类型
const ( ActionKill ActionType = "kill" ActionCheck ActionType = "check" ActionProtect ActionType = "protect" ActionPoison ActionType = "poison" ActionAntidote ActionType = "antidote" ActionShoot ActionType = "shoot" ActionSpeak ActionType = "speak" ActionVote ActionType = "vote" ActionLastWords ActionType = "last_words" )
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine 简化的游戏引擎 核心原则: 1. 不管理连接,只管理游戏状态 2. 通过事件通知游戏进展 3. 接受方法调用来处理行动
func (*Engine) AdvancePhase ¶
AdvancePhase 推进到下一个阶段(测试用)
func (*Engine) CheckWinCondition ¶
CheckWinCondition 检查胜利条件
func (*Engine) GetPlayerState ¶
func (e *Engine) GetPlayerState(playerID string) (PlayerState, error)
GetPlayerState 获取单个玩家状态
func (*Engine) KillPlayer ¶
KillPlayer 杀死玩家(测试用)
func (*Engine) PerformAction ¶
func (e *Engine) PerformAction(playerID string, actionType ActionType, targetID string, data map[string]interface{}) error
PerformAction 执行玩家行动
func (*Engine) Subscribe ¶
func (e *Engine) Subscribe(eventType EventType, handler EventHandler) SubscriptionID
Subscribe 订阅游戏事件
type EventType ¶
EventType alias for event.EventType
const ( // 游戏生命周期事件 EventGameStarted EventType = "game.started" EventGameEnded EventType = "game.ended" EventPhaseStarted EventType = "phase.started" EventPhaseEnded EventType = "phase.ended" EventRoundChanged EventType = "round.changed" // 玩家事件 EventPlayerDied EventType = "player.died" EventPlayerRevived EventType = "player.revived" EventPlayerProtected EventType = "player.protected" // 行动事件 EventActionExecuted EventType = "action.executed" EventSkillUsed EventType = "skill.used" EventVoteResult EventType = "vote.result" // 特殊事件 EventHunterShot EventType = "hunter.shot" EventLastWords EventType = "last.words" )
游戏事件类型常量
type GameState ¶
type GameState struct {
Phase PhaseType
Round int
Players []PlayerState
AlivePlayers []string
Winner Camp
IsEnded bool
}
GameState 游戏状态快照(只读)
type PlayerState ¶
PlayerState 玩家状态(只读快照)
type Role ¶
type Role interface {
// GetName returns role name
GetName() RoleType
// GetCamp returns role's camp
GetCamp() Camp
// GetAvailableSkills returns available skills in specific phase
GetAvailableSkills(phase PhaseType) []Skill
// GetPriority returns role's action priority in specific phase
GetPriority(phase PhaseType) int
}
Role interface defines role behavior
type Skill ¶
type Skill interface {
// GetName 获取技能名称
GetName() SkillType
// GetPhase 获取技能使用阶段
GetPhase() PhaseType
// GetPriority 获取技能优先级
GetPriority() int
// CanUseMultipleTimes 技能是否可以多次使用
CanUseMultipleTimes() bool
// RequiresTarget 技能是否需要目标
RequiresTarget() bool
}
Skill 技能接口
type SkillType ¶
type SkillType string
SkillType represents skill type
const ( SkillTypeKill SkillType = "kill" // Kill skill SkillTypeCheck SkillType = "check" // Check skill SkillTypeProtect SkillType = "protect" // Protect skill SkillTypeAntidote SkillType = "antidote" // Antidote skill SkillTypePoison SkillType = "poison" // Poison skill SkillTypeVote SkillType = "vote" // Vote skill SkillTypeSpeak SkillType = "speak" // Speak skill SkillTypeShoot SkillType = "shoot" // Hunter shoot skill )
Click to show internal directories.
Click to hide internal directories.