single

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2024 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Game

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

Game represents a single player game of Tetris. This can be used for Marathon, Sprint, Ultra and other single player modes.

func NewGame

func NewGame(in *Input) (*Game, error)

func (*Game) EndGame

func (g *Game) EndGame()

EndGame sets Game.gameOver to true.

func (*Game) GetBagTetriminos

func (g *Game) GetBagTetriminos() []tetris.Tetrimino

func (*Game) GetDefaultFallInterval

func (g *Game) GetDefaultFallInterval() time.Duration

func (*Game) GetHoldTetrimino

func (g *Game) GetHoldTetrimino() *tetris.Tetrimino

func (*Game) GetLevel

func (g *Game) GetLevel() int

func (*Game) GetLinesCleared

func (g *Game) GetLinesCleared() int

func (*Game) GetTotalScore

func (g *Game) GetTotalScore() int

func (*Game) GetVisibleMatrix

func (g *Game) GetVisibleMatrix() (tetris.Matrix, error)

func (*Game) HardDrop

func (g *Game) HardDrop() (bool, error)

func (*Game) Hold

func (g *Game) Hold() (bool, error)

Hold will swap the current Tetrimino with the hold Tetrimino. If the hold Tetrimino is empty, the current Tetrimino is placed in the hold slot and the setupNewTetInPlay Tetrimino is drawn. If not allowed to hold, no action is taken. If true is returned the game is over.

func (*Game) IsGameOver

func (g *Game) IsGameOver() bool

func (*Game) MoveLeft

func (g *Game) MoveLeft()

func (*Game) MoveRight

func (g *Game) MoveRight()

func (*Game) Rotate

func (g *Game) Rotate(clockwise bool) error

func (*Game) TickLower

func (g *Game) TickLower() (bool, error)

TickLower moves the current Tetrimino down one row. This should be triggered at a regular interval calculated using Fall. If the Tetrimino cannot move down, it is locked in place and true is returned. Game Over is updated if needed.

func (*Game) ToggleSoftDrop

func (g *Game) ToggleSoftDrop() time.Duration

ToggleSoftDrop toggles the Soft Drop state of the game. If Soft Drop is enabled, the game will calculate the number of lines cleared and add them to the score. The time interval for the Fall system is returned.

type Input

type Input struct {
	Level         int  // The starting level of the game.
	MaxLevel      int  // The maximum level the game can reach. 0 means no limit.
	IncreaseLevel bool // Whether the level should increase as the game progresses.
	EndOnMaxLevel bool // Whether the game should end when the maximum level is reached.

	MaxLines      int  // The maximum number of lines to clear before the game ends. 0 means no limit.
	EndOnMaxLines bool // Whether the game should end when the maximum number of lines is cleared.

	GhostEnabled bool // Whether the ghost Tetrimino should be displayed.
}

Jump to

Keyboard shortcuts

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