uno

package module
v0.0.0-...-69929ab Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2019 License: MIT Imports: 9 Imported by: 0

README

go-seabird-uno

This is a plugin for use with go-seabird which adds support for running uno games in channels.

It was originally bundled with the repo, but it got big enough where it makes sense to split it out.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewGame

func NewGame(u *plugins.User) (*Game, []*Message)

NewGame creates a game, adds the given user as the owner, and as the first user in the player ring.

Types

type Card

type Card interface {
	// Playable returns true if the card can be played right now and
	// false if it can't. It assumes that the game knows that this is
	// in the hand of the current player.
	Playable(*Game) bool

	// Play applies the effects of this card. It assumes Playable has
	// already been checked. It returns messages explaining additional
	// actions which happened. The plugin will handle basic "[user]
	// played a [card]" and "It is now [user]'s turn" messages.
	Play(*Game) []*Message

	// Color returns the color of this card.
	Color() ColorCode

	// Symbol representing this card.
	Symbol() string

	// String returns how this card should be displayed to players.
	String() string
}

Card is a generic interface for all cards.

type ColorChangeNotifier

type ColorChangeNotifier interface {
	ColorChanged(*Game) []*Message
}

ColorChangeNotifier is meant to add onto the Card interface. It defines what happens when a color is set. This is needed for the Wild cards so they can advance the turn after a color is set.

type ColorCode

type ColorCode int

ColorCode represents the color of a card.

const (
	ColorNone ColorCode = iota
	ColorWild
	ColorRed
	ColorGreen
	ColorBlue
	ColorYellow
)

Each color in here can be used on a card. ColorNone is a special color mearning the color is unknown and ColorWild means the card doesn't have a color.

func ColorCodeFromString

func ColorCodeFromString(color string) ColorCode

ColorCodeFromString tries to look up a ColorCode for any given string.

func (ColorCode) String

func (cc ColorCode) String() string

type DrawFourWildCard

type DrawFourWildCard struct {
	WildCard
}

DrawFourWildCard represents a draw four wild.

func NewDrawFourWildCard

func NewDrawFourWildCard() *DrawFourWildCard

NewDrawFourWildCard creates a new draw four wild.

func (*DrawFourWildCard) ColorChanged

func (c *DrawFourWildCard) ColorChanged(g *Game) []*Message

ColorChanged implements (ColorChangeNotifier).Color. This overrides the embedded (WildCard).ColorChanged method.

func (*DrawFourWildCard) Playable

func (c *DrawFourWildCard) Playable(g *Game) bool

Playable implements (Card).Playable. This overrides the embedded (WildCard).Playable method.

type DrawTwoCard

type DrawTwoCard struct {
	SimpleCard
}

DrawTwoCard represents a draw two

func NewDrawTwoCard

func NewDrawTwoCard(color ColorCode) *DrawTwoCard

NewDrawTwoCard creates a new draw two given a color

func (*DrawTwoCard) Play

func (c *DrawTwoCard) Play(g *Game) []*Message

Play implements (Card).Play

type Game

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

Game represents an Uno game.

func (*Game) AddPlayer

func (g *Game) AddPlayer(u *plugins.User) []*Message

AddPlayer only works if the game has not been started yet. It will add the player to the list of players.

func (*Game) Draw

func (g *Game) Draw(u *plugins.User) []*Message

Draw makes the given player draw a card.

func (*Game) DrawPlay

func (g *Game) DrawPlay(u *plugins.User, action string) []*Message

DrawPlay can only be called after a draw and mostly matters if their card is playable.

func (*Game) GetHand

func (g *Game) GetHand(u *plugins.User) []*Message

GetHand will return the hand for the current user.

func (*Game) Play

func (g *Game) Play(u *plugins.User, card string) ([]*Message, bool)

Play will handle a user playing a card. It will return messages along with if the game is now over.

func (*Game) SayUno

func (g *Game) SayUno(u *plugins.User) []*Message

SayUno handles both a user calling Uno for themselves or on other people

func (*Game) SetColor

func (g *Game) SetColor(u *plugins.User, color string) []*Message

SetColor is a callback used by the wilds.

func (*Game) Start

func (g *Game) Start(u *plugins.User) []*Message

Start will handle setup and starting a game.

func (*Game) Stop

func (g *Game) Stop(u *plugins.User) ([]*Message, bool)

Stop will handle cleaning up a game. Only the owner can do this. If the owner has left, this can be done by anyone.

type Message

type Message struct {
	// Target is the user who this message should be sent to. It
	// should be nil if it should be sent to everyone.
	Target *plugins.User

	// Message contains the contents of the message
	Message string

	// Private means that the message should be sent privately, rather
	// than to the channel. This can only be used if Target is
	// non-nil.
	Private bool
}

Message represents a message to be sent to at least one person.

type ReverseCard

type ReverseCard struct {
	SimpleCard
}

ReverseCard represents a reverse

func NewReverseCard

func NewReverseCard(color ColorCode) *ReverseCard

NewReverseCard creates a new reverse given a color

func (*ReverseCard) Play

func (c *ReverseCard) Play(g *Game) []*Message

Play implements (Card).Play

type SimpleCard

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

SimpleCard represents a 0-9

func (*SimpleCard) Color

func (c *SimpleCard) Color() ColorCode

Color implements (Card).Color

func (*SimpleCard) Play

func (c *SimpleCard) Play(g *Game) []*Message

Play implements (Card).Play

func (*SimpleCard) Playable

func (c *SimpleCard) Playable(g *Game) bool

Playable implements (Card).Playable

func (*SimpleCard) String

func (c *SimpleCard) String() string

func (*SimpleCard) Symbol

func (c *SimpleCard) Symbol() string

Symbol implements (Card).Symbol

type SkipCard

type SkipCard struct {
	SimpleCard
}

SkipCard represents a skip

func NewSkipCard

func NewSkipCard(color ColorCode) *SkipCard

NewSkipCard creates a new skip given a color

func (*SkipCard) Play

func (c *SkipCard) Play(g *Game) []*Message

Play implements (Card).Play

type WildCard

type WildCard struct {
	SimpleCard
}

WildCard represents a wild

func NewWildCard

func NewWildCard() *WildCard

NewWildCard creates a new wild

func (*WildCard) ColorChanged

func (c *WildCard) ColorChanged(g *Game) []*Message

ColorChanged implements (ColorChangeNotifier).ColorChanged

func (*WildCard) Play

func (c *WildCard) Play(g *Game) []*Message

Play implements (Card).Play. This overrides the embedded (SimpleCard).Play method.

func (*WildCard) Playable

func (c *WildCard) Playable(g *Game) bool

Playable implements (Card).Playable. This overrides the embedded (SimpleCard).Playable method.

func (*WildCard) String

func (c *WildCard) String() string

Jump to

Keyboard shortcuts

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