game

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2021 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package game provides a simple Tetris implementation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action int

Action is an action which can be taken in the game

const (
	ActionTurn Action = iota
	ActionLeft
	ActionRight
	ActionSleep
)

List of possible actions

type Board

type Board [22][10]int

Board holding the tetris blocks

func NewBoard

func NewBoard() *Board

NewBoard creates an empty board

type Game

type Game interface {
	Score() int
	Step(Action) *StepResult
	DoAction(Action)
	Board() *Board
}

Game interface for the tetris game

func NewGame

func NewGame() Game

NewGame create a new Tetris game

type Piece

type Piece struct {
	Shape *Shape
	Type  PieceType
}

Piece tetris piece which can be moved

type PieceType

type PieceType int

PieceType type of a Tetris piece

const (
	IType PieceType = iota
	JType
	LType
	OType
	SType
	TType
	ZType
)

Different piece types

type Point

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

Point point of a shape

type Shape

type Shape [4]Point

Shape shape of a piece consisting of 4 points

type StepResult

type StepResult struct {
	GameOver            bool
	Action              Action
	Board               *Board
	Collided            bool
	CompletedLinesStep  int
	CompletedLinesTotal int
	Score               int
}

StepResult result of performing a step in the game

type Tetris

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

Tetris the game implementation

func (*Tetris) Board

func (g *Tetris) Board() *Board

Board retrieves the current board

func (*Tetris) DoAction

func (g *Tetris) DoAction(a Action)

DoAction perform given action

func (*Tetris) Score

func (g *Tetris) Score() int

Score retrieves the current score

func (*Tetris) Step

func (g *Tetris) Step(a Action) *StepResult

Step perform a game step

Jump to

Keyboard shortcuts

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