core

package
v0.0.0-...-13c5eef Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoValueByKey = errors.New("no value by key in storage")

Functions

func BorderTable

func BorderTable(i int) [][]rune

Types

type Direction

type Direction int
const (
	Left Direction = iota
	Right
	Up
	Down
)

func (Direction) String

func (d Direction) String() string

type DummyHandler

type DummyHandler struct{}

func (DummyHandler) AnimationRequest

func (DummyHandler) AnimationRequest(tiles []*Tile)

func (DummyHandler) Init

func (DummyHandler) Init(size Point)

func (DummyHandler) Message

func (DummyHandler) Message(MessageKind)

func (DummyHandler) UpdateBestScore

func (DummyHandler) UpdateBestScore(bestScore int)

func (DummyHandler) UpdateScore

func (DummyHandler) UpdateScore(score int)

type GameManager

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

func NewGameManager

func NewGameManager(storage Storage, handler Handler) *GameManager

func (*GameManager) Draw

func (gm *GameManager) Draw()

func (*GameManager) KeepPlaying

func (gm *GameManager) KeepPlaying()

Keep playing after winning (allows going over 2048)

func (*GameManager) Move

func (gm *GameManager) Move(d Direction)

Move tiles on the grid in the specified direction

func (*GameManager) PrintableGrid

func (gm *GameManager) PrintableGrid() []byte

func (*GameManager) Restart

func (gm *GameManager) Restart()

Restart the game

func (*GameManager) UndoMove

func (gm *GameManager) UndoMove()

type Handler

type Handler interface {
	Init(size Point)
	AnimationRequest(tiles []*Tile)
	UpdateScore(score int)
	UpdateBestScore(bestScore int)
	Message(MessageKind)
}

type InputManager

type InputManager interface {
	Restart()
	KeepPlaying()
	Move(d Direction)
	UndoMove()
	Draw()
}

type MapStorage

type MapStorage map[string][]byte

func NewMapStorage

func NewMapStorage() *MapStorage

func (*MapStorage) Get

func (ms *MapStorage) Get(key string) (val []byte, err error)

func (*MapStorage) Put

func (ms *MapStorage) Put(key string, val []byte) error

func (*MapStorage) Remove

func (ms *MapStorage) Remove(key string) error

type MessageKind

type MessageKind int
const (
	MK_CLEAR    MessageKind = iota // Clear the game won/lost message
	MK_YOU_LOSE                    // You lose
	MK_YOU_WIN                     // You win!
)

func (MessageKind) String

func (mk MessageKind) String() string

type Point

type Point = image.Point

func DefaultSize

func DefaultSize() Point

func MakePoint

func MakePoint(x, y int) Point

type Storage

type Storage interface {
	Put(key string, value []byte) error
	Get(key string) (value []byte, err error)
	Remove(key string) error
}

type StorageManager

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

func NewStorageManager

func NewStorageManager(storage Storage) *StorageManager

type Tile

type Tile struct {
	Position Point
	Value    int

	PreviousPosition *Point  `json:"-"`
	MergedFrom       []*Tile `json:"-"`
}

Jump to

Keyboard shortcuts

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