phase

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 10, 2025 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BasePhase

type BasePhase struct {
	// contains filtered or unexported fields
}

BasePhase 基础阶段实现 提供通用的阶段功能

func NewBasePhase

func NewBasePhase(name werewolf.PhaseType) *BasePhase

NewBasePhase 创建基础阶段

func (*BasePhase) AddActionToList

func (b *BasePhase) AddActionToList(action PhaseAction)

AddActionToList 添加行动到列表(供子类使用)

func (*BasePhase) GetActions

func (b *BasePhase) GetActions() []PhaseAction

GetActions 获取所有行动

func (*BasePhase) GetAlivePlayersByRole

func (b *BasePhase) GetAlivePlayersByRole(role werewolf.RoleType, players []PhasePlayer) []PhasePlayer

GetAlivePlayersByRole 获取指定角色的存活玩家

func (*BasePhase) GetAlivePlayersCount

func (b *BasePhase) GetAlivePlayersCount(players []PhasePlayer) int

GetAlivePlayersCount 获取存活玩家数量

func (*BasePhase) GetName

func (b *BasePhase) GetName() werewolf.PhaseType

GetName 获取阶段名称

func (*BasePhase) GetPlayerByID

func (b *BasePhase) GetPlayerByID(playerID string, players []PhasePlayer) *PhasePlayer

GetPlayerByID 根据ID获取玩家

func (*BasePhase) GetRound

func (b *BasePhase) GetRound() int

GetRound 获取回合数

func (*BasePhase) HasPlayerActed

func (b *BasePhase) HasPlayerActed(playerID string) bool

HasPlayerActed 检查玩家是否已行动

func (*BasePhase) Reset

func (b *BasePhase) Reset()

Reset 重置阶段状态

func (*BasePhase) ValidatePlayer

func (b *BasePhase) ValidatePlayer(playerID string, players []PhasePlayer) error

ValidatePlayer 验证玩家是否可以行动

func (*BasePhase) ValidateTarget

func (b *BasePhase) ValidateTarget(targetID string, players []PhasePlayer, requireAlive bool) error

ValidateTarget 验证目标玩家是否有效

type DayPhase

type DayPhase struct {
	*BasePhase
	// contains filtered or unexported fields
}

DayPhase 白天阶段 主要用于玩家发言讨论,不强制要求行动

func NewDayPhase

func NewDayPhase() *DayPhase

NewDayPhase 创建白天阶段

func (*DayPhase) AddAction

func (d *DayPhase) AddAction(action PhaseAction, players []PhasePlayer) error

AddAction 添加玩家行动

func (*DayPhase) IsComplete

func (d *DayPhase) IsComplete(players []PhasePlayer) bool

IsComplete 检查白天阶段是否完成

func (*DayPhase) Process

func (d *DayPhase) Process(players []PhasePlayer) (PhaseResult, error)

Process 处理白天阶段

func (*DayPhase) Reset

func (d *DayPhase) Reset()

Reset 重置白天阶段

func (*DayPhase) Start

func (d *DayPhase) Start(players []PhasePlayer, round int) (bool, error)

Start 开始白天阶段

type NightPhase

type NightPhase struct {
	*BasePhase
	// contains filtered or unexported fields
}

NightPhase 夜晚阶段 处理狼人杀人、预言家查验、女巫用药、守卫守护等行动

func NewNightPhase

func NewNightPhase() *NightPhase

NewNightPhase 创建夜晚阶段

func (*NightPhase) AddAction

func (n *NightPhase) AddAction(action PhaseAction, players []PhasePlayer) error

AddAction 添加玩家行动

func (*NightPhase) IsComplete

func (n *NightPhase) IsComplete(players []PhasePlayer) bool

IsComplete 检查夜晚阶段是否完成

func (*NightPhase) Process

func (n *NightPhase) Process(players []PhasePlayer) (PhaseResult, error)

Process 处理夜晚阶段

func (*NightPhase) Reset

func (n *NightPhase) Reset()

Reset 重置夜晚阶段

func (*NightPhase) Start

func (n *NightPhase) Start(players []PhasePlayer, round int) (bool, error)

Start 开始夜晚阶段

type Phase

type Phase interface {
	// GetName 获取阶段名称
	GetName() werewolf.PhaseType

	// Start 开始阶段
	// 返回是否需要玩家行动
	Start(players []PhasePlayer, round int) (requiresAction bool, error error)

	// AddAction 添加玩家行动
	// 返回行动是否有效
	AddAction(action PhaseAction, players []PhasePlayer) error

	// IsComplete 检查阶段是否完成
	// 判断是否所有必要的行动都已收集
	IsComplete(players []PhasePlayer) bool

	// Process 处理阶段
	// 执行阶段逻辑,计算结果
	Process(players []PhasePlayer) (PhaseResult, error)

	// Reset 重置阶段状态
	// 准备下一次使用
	Reset()
}

Phase 阶段接口 定义每个游戏阶段必须实现的方法

type PhaseAction

type PhaseAction struct {
	PlayerID   string                 // 行动玩家ID
	ActionType werewolf.ActionType    // 行动类型
	TargetID   string                 // 目标玩家ID(可选)
	Data       map[string]interface{} // 额外数据
}

PhaseAction 表示玩家在阶段中的一个行动

type PhasePlayer

type PhasePlayer struct {
	ID          string
	Role        werewolf.RoleType
	IsAlive     bool
	IsProtected bool
}

PhasePlayer 阶段中的玩家信息(简化版)

type PhaseResult

type PhaseResult struct {
	DeadPlayers []string               // 本阶段死亡的玩家ID列表
	VoteResult  map[string]int         // 投票结果(投票阶段使用)
	Data        map[string]interface{} // 其他结果数据
}

PhaseResult 阶段处理结果

type VotePhase

type VotePhase struct {
	*BasePhase
	// contains filtered or unexported fields
}

VotePhase 投票阶段 所有存活玩家投票驱逐一名玩家

func NewVotePhase

func NewVotePhase() *VotePhase

NewVotePhase 创建投票阶段

func (*VotePhase) AddAction

func (v *VotePhase) AddAction(action PhaseAction, players []PhasePlayer) error

AddAction 添加玩家行动

func (*VotePhase) IsComplete

func (v *VotePhase) IsComplete(players []PhasePlayer) bool

IsComplete 检查投票阶段是否完成

func (*VotePhase) Process

func (v *VotePhase) Process(players []PhasePlayer) (PhaseResult, error)

Process 处理投票阶段

func (*VotePhase) Reset

func (v *VotePhase) Reset()

Reset 重置投票阶段

func (*VotePhase) Start

func (v *VotePhase) Start(players []PhasePlayer, round int) (bool, error)

Start 开始投票阶段

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL