blackjack

package
v0.0.0-...-7e13a96 Latest Latest
Warning

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

Go to latest
Published: May 28, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Load

func Load()

Load : load game from JSON

Types

type Blackjack

type Blackjack struct {
	Deck       *Deck   `json:"deck"`       // deck of cards
	Dealer     *Dealer `json:"dealer"`     // dealer struct
	Player     *Player `json:"player"`     // player struct
	State      string  `json:"state"`      // game state (over or in progress)
	PlayerSum  int     `json:"playerSum"`  // player hand sum
	DealerSum  int     `json:"dealerSum"`  // dealer hand sum
	LastAction string  `json:"lastAction"` // last player action
}

Blackjack : will have a player, a dealer and a deck

func Init

func Init(playerName string) Blackjack

Init : initialize blackjack game

func (*Blackjack) Another

func (b *Blackjack) Another()

Another : play another round of a given game

func (*Blackjack) Check

func (b *Blackjack) Check()

Check : check if there is a winner

func (*Blackjack) Deal

func (b *Blackjack) Deal()

Deal : deal cards

func (*Blackjack) Display

func (b *Blackjack) Display()

Display : show game info

func (*Blackjack) Play

func (b *Blackjack) Play(playerAction string)

Play : blackjack game play

func (*Blackjack) Result

func (b *Blackjack) Result()

func (*Blackjack) Save

func (b *Blackjack) Save()

Save : save game to JSON

type Card

type Card struct {
	Suite string `json:"suite"`
	Name  string `json:"name"`
	Value int    `json:"value"`
}

Card : atomic component of deck

type Dealer

type Dealer struct {
	Drawn []Card `json:"drawn"`
}

Dealer : struct to maintain dealer drawn cards

func (*Dealer) Hit

func (d *Dealer) Hit(deck *Deck)

Hit : draw a card from a deck

func (*Dealer) Refresh

func (d *Dealer) Refresh()

Refresh : remove any drawn cards from dealer

type Deck

type Deck struct {
	Cards  []Card
	Dealt  []Card
	Suites []string `json:"suites"`
	Names  []string `json:"names"`
	Values []int    `json:"values"`
}

Deck : collection of cards

func MakeDeck

func MakeDeck() Deck

MakeDeck : makes a deck

func (*Deck) Draw

func (d *Deck) Draw() Card

Draw : draw a card from a deck

func (*Deck) Shuffle

func (d *Deck) Shuffle()

Shuffle : unshuffled cards are no fun so randomise their order

type Player

type Player struct {
	Wallet     int    `json:"wallet"`
	Drawn      []Card `json:"drawn"`
	Name       string `json:"name"`
	CurrentBet int    `json:"currentBet"`
}

Player : struct to maintain player wallet, bets and drawn cards

func (*Player) Bet

func (p *Player) Bet(betAmount int) error

Bet : place a bet & subtract amount from Deck

func (*Player) Hit

func (p *Player) Hit(d *Deck)

Hit : draw a card from a deck

func (*Player) Refresh

func (p *Player) Refresh()

Refresh : remove any drawn cards from player

Jump to

Keyboard shortcuts

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