Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type BattleStorage ¶
type BattleStorage interface { // GetBattle returns battle instance for given gameID from storage. Returns nil // when battle instance is not found. GetBattle(ctx context.Context, gameID string) (*entity.Battle, error) // SaveBattle is used for saving given battle instance into storage. If battle // instance is already exists in the storage, it will be overwritten. SaveBattle(ctx context.Context, b entity.Battle) error }
type GameStorage ¶
type GameStorage interface { // GetGame returns game instance for given gameID from storage. Returns nil // when given gameID is not found in database. GetGame(ctx context.Context, gameID string) (*entity.Game, error) // Save is used for saving game instance in storage. SaveGame(ctx context.Context, game entity.Game) error }
type MonsterStorage ¶
type Service ¶
type Service interface { // StartBattle is used for starting new battle for given game id. Battle could only // be started when there is no previous battle or it is already ended. StartBattle(ctx context.Context, gameID string) (*entity.Battle, error) // GetBattle returns ongoing battle for given game id. GetBattle(ctx context.Context, gameID string) (*entity.Battle, error) // DecideTurn is used for deciding turn for the battle. There are 3 possible outcome // battle states from this action: // // - DECIDE_TURN => partner has been attacked by enemy but still not lose, so the state // returned back to DECIDE_TURN // - LOSE => partner has been attacked by enemy and already lose // - PARTNER_TURN => it is partner turn, client may commence attack or surrender DecideTurn(ctx context.Context, gameID string) (*entity.Battle, error) // Attack is used for executing attack to enemy. The possible battle state outcome // is DECIDE_TURN or WIN. Attack(ctx context.Context, gameID string) (*entity.Battle, error) // Surrender is used for executing surrender action. Battle will immediately ended // with player losing the battle. Surrender(ctx context.Context, gameID string) (*entity.Battle, error) }
func NewService ¶
func NewService(cfg ServiceConfig) (Service, error)
NewService returns new instance of service.
type ServiceConfig ¶
type ServiceConfig struct { GameStorage GameStorage `validate:"nonnil"` BattleStorage BattleStorage `validate:"nonnil"` MonsterStorage MonsterStorage `validate:"nonnil"` }
func (ServiceConfig) Validate ¶
func (c ServiceConfig) Validate() error
Click to show internal directories.
Click to hide internal directories.