Documentation ¶
Index ¶
Constants ¶
const MinDamage = 5
Variables ¶
var ErrInvalidState = errors.New("invalid state for given action")
Functions ¶
This section is empty.
Types ¶
type Battle ¶
type Battle struct { GameID string State State Partner *Monster Enemy *Monster LastDamage LastDamage }
func NewBattle ¶
func NewBattle(cfg BattleConfig) (*Battle, error)
NewBattle returns new instance of Battle based on given config.
func (*Battle) DecideTurn ¶
DecideTurn is used for deciding turn in the battle. It calculates turn based on speed of both partner & enemy. The battle state must be DECIDE_TURN, otherwise the action will be rejected.
func (*Battle) EnemyAttack ¶
EnemyAttack is used for executing enemy attack. The battle state must be ENEMY_TURN otherwise the action will be rejected.
func (*Battle) PartnerAttack ¶
PartnerAttack is used for executing partner attack. The battle state must be PARTNER_TURN otherwise the action will be rejected.
func (*Battle) PartnerSurrender ¶
PartnerSurrender is used for executing partner surrender. The battle state must be PARTNER_TURN otherwise the action will be rejected.
type BattleConfig ¶
type BattleConfig struct { GameID string `validate:"nonzero"` Partner *Monster `validate:"nonnil"` Enemy *Monster `validate:"nonnil"` }
func (BattleConfig) Validate ¶
func (c BattleConfig) Validate() error
type BattleStats ¶
type Game ¶
type Game struct { ID string PlayerName string Partner *Monster CreatedAt int64 BattleWon int Scenario Scenario }
func NewGame ¶
func NewGame(cfg GameConfig) (*Game, error)
func (*Game) AdvanceScenario ¶
AdvanceScenario is used for advancing current game scenario. It will calculate the next scenario based on game current condition. Beside updating game internal scenario into the new one, it also returns the new scenario value.
func (*Game) IncBattleWon ¶
func (g *Game) IncBattleWon()
IncBattleWon is used for incrementing number of battle won then advancing the scenario
type GameConfig ¶
type GameConfig struct { PlayerName string `validate:"nonzero"` Partner *Monster `validate:"nonnil"` CreatedAt int64 `validate:"nonzero"` }
func (GameConfig) Validate ¶
func (c GameConfig) Validate() error
type LastDamage ¶
type Monster ¶
type Monster struct { ID string Name string BattleStats BattleStats AvatarURL string }
func (*Monster) InflictDamage ¶
InflictDamage is used for inflicting damage to self based on given enemy. Returned the damage amount.
func (*Monster) ResetBattleStats ¶
func (p *Monster) ResetBattleStats()
ResetBattleStats is used to reset partner health after lost or surrender from the battle