entity

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const MinDamage = 5

Variables

View Source
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

func (b *Battle) DecideTurn() (State, error)

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

func (b *Battle) EnemyAttack() error

EnemyAttack is used for executing enemy attack. The battle state must be ENEMY_TURN otherwise the action will be rejected.

func (Battle) IsEnded

func (b Battle) IsEnded() bool

IsEnded returns true when state is either WIN or LOSE

func (*Battle) PartnerAttack

func (b *Battle) PartnerAttack() error

PartnerAttack is used for executing partner attack. The battle state must be PARTNER_TURN otherwise the action will be rejected.

func (*Battle) PartnerSurrender

func (b *Battle) PartnerSurrender() error

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 BattleStats struct {
	Health    int
	MaxHealth int
	Attack    int
	Defense   int
	Speed     int
}

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

func (g *Game) AdvanceScenario() Scenario

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 LastDamage struct {
	Partner int
	Enemy   int
}

type Monster

type Monster struct {
	ID          string
	Name        string
	BattleStats BattleStats
	AvatarURL   string
}

func (*Monster) InflictDamage

func (p *Monster) InflictDamage(enemy Monster) int

InflictDamage is used for inflicting damage to self based on given enemy. Returned the damage amount.

func (Monster) IsDead

func (p Monster) IsDead() bool

func (*Monster) ResetBattleStats

func (p *Monster) ResetBattleStats()

ResetBattleStats is used to reset partner health after lost or surrender from the battle

type Scenario

type Scenario string
const (
	ScenarioBattle1 Scenario = "BATTLE_1"
	ScenarioBattle2 Scenario = "BATTLE_2"
	ScenarioBattle3 Scenario = "BATTLE_3"
	ScenarioEndGame Scenario = "END_GAME"
)

type State

type State string

State represents current battle state

const (
	StateDecideTurn  State = "DECIDE_TURN"
	StateEnemyTurn   State = "ENEMY_TURN"
	StatePartnerTurn State = "PARTNER_TURN"
	StateWin         State = "WIN"
	StateLose        State = "LOSE"
)

Jump to

Keyboard shortcuts

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