model

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrGameAlreadyPlaying  = errors.New("game is already playing")
	ErrGameAlreadyFinished = errors.New("game is already finished")
	ErrGameNotPlaying      = errors.New("game is not playing")
)
View Source
var (
	ErrInsufficientCoins = errors.New("insufficient coins")
)
View Source
var (
	ErrUserDeactivated = errors.New("user is deactivated")
)

Functions

This section is empty.

Types

type Coins

type Coins int

Coins は、ゲーム内通貨を表します。

func NewCoins

func NewCoins(v int) (Coins, error)

func (Coins) IsZero

func (c Coins) IsZero() bool

type Echo

type Echo struct {
	ID        uuid.UUID
	Message   string
	Timestamp time.Time
}

func NewEcho

func NewEcho(message string, timestamp time.Time) Echo

type GameID

type GameID int
const (
	GameIDSolitaire GameID = iota + 1
	GameIDBlackjack
	GameIDJanken
)

type GameResult

type GameResult int
const (
	GameResultUnknown GameResult = iota
	GameResultWin
	GameResultLose
	GameResultDraw
)

type GameSession

type GameSession struct {
	ID         uuid.UUID
	UserID     uuid.UUID
	GameID     GameID
	Status     GameStatus
	Result     GameResult
	Wager      Coins
	Payout     Coins
	StartedAt  time.Time
	FinishedAt time.Time
}

GameSession は、PvE ゲームのセッションを表します。

func NewGameSession

func NewGameSession(id uuid.UUID, userID uuid.UUID, gameID GameID, status GameStatus, result GameResult, wager Coins, payout Coins, startedAt time.Time, finishedAt time.Time) (GameSession, error)

func (*GameSession) FinishPlaying

func (g *GameSession) FinishPlaying(result GameResult, now time.Time) (Coins, error)

func (GameSession) IsPlaying

func (g GameSession) IsPlaying() bool

type GameSessionStartService

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

func NewGameSessionService

func NewGameSessionService(ctx context.Context, userID uuid.UUID, playingSessions []GameSession) (GameSessionStartService, error)

func (*GameSessionStartService) StartPlaying

func (s *GameSessionStartService) StartPlaying(id uuid.UUID, gameID GameID, wager Coins, now time.Time) (GameSession, error)

type GameStatus

type GameStatus int
const (
	GameStatusPlaying GameStatus = iota + 1
	GameStatusFinished
)

type JankenHand

type JankenHand int
const (
	JankenHandRock JankenHand = iota + 1
	JankenHandScissors
	JankenHandPaper
)

func (JankenHand) Battle

func (mine JankenHand) Battle(opponent JankenHand) GameResult

type JankenHistory

type JankenHistory struct {
	Turn         int
	MyHand       JankenHand
	OpponentHand JankenHand
}

func NewJankenHistory

func NewJankenHistory(turn int, myHand JankenHand, opponentHand JankenHand) JankenHistory

type JankenSession

type JankenSession struct {
	GameSessionID uuid.UUID
	Seed          int
	Histories     []JankenHistory
}

func NewJankenSession

func NewJankenSession(gameSessionID uuid.UUID, seed int, histories []JankenHistory) JankenSession

func (*JankenSession) Choose

func (j *JankenSession) Choose(session GameSession, hand JankenHand, now time.Time) (GameSession, Coins, JankenHistory, error)

type JankenSessionStartService

type JankenSessionStartService struct {
	GameSessionStartService
}

func NewJankenSessionStartService

func NewJankenSessionStartService(ctx context.Context, userID uuid.UUID, playingSessions []GameSession) (JankenSessionStartService, error)

func (JankenSessionStartService) StartPlaying

func (s JankenSessionStartService) StartPlaying(id uuid.UUID, wager Coins, now time.Time) (GameSession, JankenSession, error)

type User

type User struct {
	ID     uuid.UUID
	Status UserStatus
}

func NewUser added in v0.2.0

func NewUser(id uuid.UUID, status UserStatus) User

type UserStatus added in v0.2.0

type UserStatus int
const (
	// 設定が未完了で、他ユーザには公開されていない状態。
	// サインイン後、設定を完了するまでこの状態が続く。
	UserStatusPending UserStatus = 1 + iota
	// アカウントが利用可能で、他ユーザにも公開されている状態。
	UserStatusActive
	// アカウントが削除され、利用不可な状態。
	// この状態になると、二度と利用できなくなる。
	UserStatusDeactivated
)

type Wallet

type Wallet struct {
	UserID  uuid.UUID
	Balance Coins
}

func (*Wallet) Deposit

func (w *Wallet) Deposit(coins Coins) error

func (*Wallet) Withdraw

func (w *Wallet) Withdraw(coins Coins) error

Jump to

Keyboard shortcuts

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