tetris

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

This is a simple implementation of a console-based Tetris clone. It only works where termbox-go works (linux/mac should be fine).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Board

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

A Board represents the state of a tetris game board, including the current piece that is descending and the blocks which already exist on the board.

func (*Board) CellColor

func (board *Board) CellColor(position Vector) termbox.Attribute

Finds the color of a particular board cell. It returns the background color if the cell is empty.

type ColorMap

type ColorMap map[Vector]termbox.Attribute

A map from a point on a board to the color of that cell.

type Direction

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

type Game

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

A Game tracks the entire game state of tetris, including the Board, the upcoming piece, the game speed (dropDelayMillis), the score, and various other internal data.

func NewGame

func NewGame() *Game

Initialize a new game, ready to be started with Start().

func (*Game) DrawDynamic

func (game *Game) DrawDynamic(clearOnly bool)

Draw the dynamic parts of the game interface (the board, the next piece preview pane, and the score). The static parts should be drawn with the drawStaticBoardParts() function, if needed. If clearOnly is true, the board and preview pane will be cleared rather than redrawn.

func (*Game) DrawGameOver

func (game *Game) DrawGameOver()

Draw the "GAME OVER" overlay on top of the game interface.

func (*Game) DrawPauseScreen

func (game *Game) DrawPauseScreen()

Draw the pause screen, hiding the game board and next piece.

func (*Game) GeneratePiece

func (game *Game) GeneratePiece() *Piece

Randomly choose a new game piece from among the the available pieces.

func (*Game) Move

func (game *Game) Move(where Direction)

Attempt to move.

func (*Game) PauseToggle

func (game *Game) PauseToggle()

Pause or unpause the game, depending on game.paused.

func (*Game) QuickDrop

func (game *Game) QuickDrop()

Drop the piece all the way and anchor it.

func (*Game) Rotate

func (game *Game) Rotate()

Rotates the current game piece, if possible.

func (*Game) Start

func (game *Game) Start()

Start running the game. It will continue indefinitely until the user exits.

type GameEvent

type GameEvent int

A game event, generated by user input or by the game ticker.

const (
	MoveLeft GameEvent = iota
	MoveRight
	MoveDown
	Rotate
	QuickDrop
	Pause
	Quit
	// An event that doesn't cause a change to game state but causes a full redraw; e.g., a window resize.
	Redraw
)

type Piece

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

A Tetris piece, including the all the possible rotations, a color, and an index indicating the current rotation of the piece.

type PieceInstance

type PieceInstance []Vector

A particular rotational instance of a piece.

type Vector

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

A two-dimensional integer-valued vector.

Jump to

Keyboard shortcuts

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