GitHub快速開始

API 參考取自原始碼中的 Go 文件註解,以英文撰寫。

package deck

import "github.com/nsgo-dev/game/pkg/cards/deck"

概覽

Package deck provides deterministic draw, hand, discard, and exhaust piles.

The package is experimental: its API and documented formats may change in a minor release. See the API stability policy.

索引

變數

var ErrEmpty = errors.New("deck: no cards available")

ErrEmpty reports that neither the draw pile nor the discard pile has a card left. Draw does not return it: it returns fewer cards than asked for instead.

型別

type Card struct {
	ID       string
	Cost     int
	Keywords map[string]bool
}

Card identifies a card in a deck.

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

Deck manages deterministic draw and discard piles.

func New(cards []Card, seed uint64, handLimit int) *Deck

New creates a deck from cards.

func (d *Deck) Discard(id string) error

Discard moves the first card in hand with id to the discard pile.

func (d *Deck) Draw(n int) []Card

Draw draws cards from the deck.

func (d *Deck) EndTurn()

EndTurn applies end-of-turn pile transitions.

func (d *Deck) Exhaust(id string) error

Exhaust moves the first card in hand with id to the exhaust pile, out of future draws.

func (d *Deck) Hand() []Card

Hand returns a copy of the cards currently held.

func (d *Deck) Piles() (draw, discard, exhaust []Card)

Piles returns copies of the draw, discard, and exhaust piles.