twenty48

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 20, 2018 License: MIT Imports: 4 Imported by: 0

README

Twenty48

CircleCI codecov

Play 2048 from CLI

2048 on CLI

Use up, down, left and right arrow keys to play, and ESC to quit.

The default grid size is 8x8 which can be changed be setting -width and -height flags.

$ twenty48 [-width=8] [-height=8]

Install

Requires Golang:

$ go get -u github.com/alyyousuf7/twenty48/cmd/twenty48

Development

On host machine with Golang installed:

$ make test   # execute test
$ make binary # build the executable in bin/

Or using Docker:

$ make shell  # jump into a container
root@container:/go/src/github.com/alyyousuf7/twenty48# make test
root@container:/go/src/github.com/alyyousuf7/twenty48# make binary
root@container:/go/src/github.com/alyyousuf7/twenty48# exit

The Docker container mounts a volume to bin/ to copy executable to host machine.

TODOs

  • Write more tests
  • Maintain scoreboard
  • Display game over text

PRs are most welcome!

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoEmptyCell    = fmt.Errorf("No empty cell")
	ErrNoMovePossible = fmt.Errorf("No move possible")
)

Functions

This section is empty.

Types

type Board

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

func NewBoard

func NewBoard(width, height int) *Board

func (*Board) At

func (b *Board) At(x, y int) *Cell

func (*Board) MoveDown

func (b *Board) MoveDown() error

func (*Board) MoveLeft

func (b *Board) MoveLeft() error

func (*Board) MoveRight

func (b *Board) MoveRight() error

func (*Board) MoveUp

func (b *Board) MoveUp() error

func (*Board) NewMove

func (b *Board) NewMove()

func (*Board) Size

func (b *Board) Size() (int, int)

type Cell

type Cell int

func (*Cell) Empty

func (c *Cell) Empty() bool

func (*Cell) SetValue

func (c *Cell) SetValue(v int)

func (*Cell) Value

func (c *Cell) Value() int

type Direction

type Direction int
const (
	DirectionLeft Direction = iota
	DirectionRight
	DirectionUp
	DirectionDown
)

type Grid

type Grid []Row

func (Grid) String

func (rows Grid) String() string

func (Grid) Transpose

func (rows Grid) Transpose() Grid

type Row

type Row []Cell

func (Row) Merge

func (cells Row) Merge(direction Direction) Row

Merge moves and merges cell to the left and return the new list. It returns an error if no changes are made.

func (Row) Move

func (cells Row) Move(direction Direction) Row

Move moves all the non-zero cells to a particular direction and returns a new now

func (Row) Reverse

func (cells Row) Reverse() Row

Reverse reverses all the data and returns a new row

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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