deckofcards

package module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: May 30, 2019 License: MIT Imports: 8 Imported by: 1

README

DeckOfCards GoDocBuild StatuscodecovGo Report CardMaintainability



Reason for the project

I wanted to write a library for a deck that I could use for multiple card games. I have looked at other projects but found that it was not meeting all my requirements. I also decided I wanted to use this project as an excercise for Golang modulization.

Project status

The base implementation is complete but I will add more functionality if needed.

Install

With a correctly configured Go toolchain:

go get -u github.com/heindrichpaul/deckofcards

License

MIT License. See the LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Card

type Card struct {
	Value  string `json:"value"`
	Suit   string `json:"suit"`
	Code   string `json:"code"`
	DeckID string `json:"deckId"`
	// contains filtered or unexported fields
}

Card is a type that implements the structure of a Card.

func (*Card) Equals added in v1.0.0

func (z *Card) Equals(card *Card) bool

Equals function compares two cards with each other.

func (*Card) String

func (z *Card) String() string

String function serializes the Card struct into a representable string output.

type Cards added in v1.1.0

type Cards []*Card

Cards A type that represents a slice of cards to make the code easier to read and easier to use in other type definitions

func (Cards) String added in v1.1.0

func (z Cards) String() string

type Deck

type Deck struct {
	Remaining int    `json:"remaining"`
	DeckID    string `json:"deckId"`
	Success   bool   `json:"success"`
	Shuffled  bool   `json:"shuffled"`
	// contains filtered or unexported fields
}

Deck is a type that implements the structure of a Deck.

func NewDeck

func NewDeck(amount int) *Deck

NewDeck creates an unshuffled amount of decks requested by the parameter (amount). These decks do not contain jokers.

func NewDeckWithJokers added in v1.0.2

func NewDeckWithJokers(amount int) *Deck

NewDeckWithJokers creates an unshuffled amount of decks requested by the parameter (amount). These decks do contain jokers.

func ShuffleDeck

func ShuffleDeck(deck *Deck) *Deck

ShuffleDeck shuffles the deck that has been passed as a parameter.

func UnmarshalDeck

func UnmarshalDeck(data []byte) (*Deck, error)

UnmarshalDeck unmarshals a byte array into a pointer to a Deck for internal use.

func (*Deck) Draw

func (z *Deck) Draw(amount int) (draw *Draw)

Draw draws the amount of requested cards from the current deck.

func (*Deck) Marshal

func (z *Deck) Marshal() ([]byte, error)

Marshal marshals a pointer to a Deck into a byte array for transmission.

func (*Deck) String

func (z *Deck) String() string

String function serializes the Deck struct into a representable string output.

type Draw

type Draw struct {
	Success   bool  `json:"success"`
	Cards     Cards `json:"cards"`
	Remaining int   `json:"remaining"`
}

Draw is a type that implements the structure of a Draw.

func UnmarshalDraw

func UnmarshalDraw(data []byte) (*Draw, error)

UnmarshalDraw unmarshals a byte array into a pointer to a Draw for internal use.

func (*Draw) AreAllCardsInThisDraw added in v1.1.0

func (z *Draw) AreAllCardsInThisDraw(cards Cards) bool

AreAllCardsInThisDraw returns true if all the cards in the cards slice are in the draw.

func (*Draw) Marshal

func (z *Draw) Marshal() ([]byte, error)

Marshal marshals a pointer to a Draw into a byte array for transmission.

func (*Draw) String

func (z *Draw) String() string

String function serializes the Draw struct into a representable string output.

type Pile

type Pile struct {
	Remaining int
	PileID    string
	// contains filtered or unexported fields
}

Pile is a type that implements the structure of a Draw.

func NewPile

func NewPile() *Pile

NewPile creates a new Pile instance an returns a pointer to it.

func ShufflePile added in v1.1.0

func ShufflePile(pile *Pile) *Pile

ShufflePile returns a shuffled pile

func UnmarshalPile added in v1.1.1

func UnmarshalPile(data []byte) (*Pile, error)

UnmarshalPile unmarshals a byte array into a pointer to a Pile for internal use.

func (*Pile) AddCardsToPile

func (z *Pile) AddCardsToPile(draw *Draw, cards Cards)

AddCardsToPile adds all the cards in the cards parameter that are present in the Draw to the pile.

func (*Pile) GetCardAtID added in v1.1.0

func (z *Pile) GetCardAtID(index int) (*Draw, error)

GetCardAtID returns the card at the id from the pile.

func (*Pile) GetCardsFromPile

func (z *Pile) GetCardsFromPile(cards Cards) *Draw

GetCardsFromPile returns the specified cards from the pile as a Draw.

func (*Pile) Marshal added in v1.1.1

func (z *Pile) Marshal() ([]byte, error)

Marshal marshals a pointer to a Pile into a byte array for transmission.

func (*Pile) PickAllCardsFromPile

func (z *Pile) PickAllCardsFromPile() *Draw

PickAllCardsFromPile returns all the cards in the pile as a Draw and clears the pile.

func (*Pile) PickAmountOfCardsFromBottomOfPile

func (z *Pile) PickAmountOfCardsFromBottomOfPile(amount int) *Draw

PickAmountOfCardsFromBottomOfPile returns a Draw of the amount selected from the bottom of the pile.

func (*Pile) PickAmountOfCardsFromTopOfPile

func (z *Pile) PickAmountOfCardsFromTopOfPile(amount int) *Draw

PickAmountOfCardsFromTopOfPile returns a Draw of the amount selected from the top of the pile.

func (*Pile) RetrieveCardsInPile

func (z *Pile) RetrieveCardsInPile() (cards Cards)

RetrieveCardsInPile returns a copy of all cards in the pile

func (*Pile) String

func (z *Pile) String() string

Jump to

Keyboard shortcuts

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