tetris

package
v0.93.0 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Modified and adapted from github.com/MichaelS11/go-tetris.git Under MIT.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ChangeBoardSize

func ChangeBoardSize(width int, height int)

ChangeBoardSize changes board size

func NewBoard

func NewBoard()

NewBoard creates a new clear board

func NewEngine

func NewEngine()

NewEngine creates new engine

func NewMinos

func NewMinos()

NewMinos creates the minos and minoBag

func NewView

func NewView()

NewView creates a new view

func Start

func Start() error

func ValidDisplayLocation

func ValidDisplayLocation(x int, y int) bool

ValidDisplayLocation checks if vaild display location

Types

type Board

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

Board is the Tetris board

func (*Board) Clear

func (board *Board) Clear()

Clear clears the board to original state

func (*Board) DrawBoard

func (board *Board) DrawBoard()

DrawBoard draws the board with help from view

func (*Board) DrawCurrentMino

func (board *Board) DrawCurrentMino()

DrawCurrentMino draws the current mino

func (*Board) DrawCursor

func (board *Board) DrawCursor(x int, y int)

DrawCursor draws the edit cursor

func (*Board) DrawDropMino

func (board *Board) DrawDropMino()

DrawDropMino draws the drop mino

func (*Board) DrawPreviewMino

func (board *Board) DrawPreviewMino()

DrawPreviewMino draws the preview mino

func (*Board) EmptyBoard

func (board *Board) EmptyBoard()

EmptyBoard removes all blocks/colors from the board

func (*Board) MinoDrop

func (board *Board) MinoDrop()

MinoDrop dropps mino

func (*Board) MinoMoveDown

func (board *Board) MinoMoveDown()

MinoMoveDown moves mino down

func (*Board) MinoMoveLeft

func (board *Board) MinoMoveLeft()

MinoMoveLeft moves mino left

func (*Board) MinoMoveRight

func (board *Board) MinoMoveRight()

MinoMoveRight moves mino right

func (*Board) MinoRotateLeft

func (board *Board) MinoRotateLeft()

MinoRotateLeft rotates mino right

func (*Board) MinoRotateRight

func (board *Board) MinoRotateRight()

MinoRotateRight rotates mino right

func (*Board) NextBoard

func (board *Board) NextBoard()

NextBoard switches to next board

func (*Board) PreviousBoard

func (board *Board) PreviousBoard()

PreviousBoard switches to previous board

func (*Board) RotateLeft

func (board *Board) RotateLeft(x int, y int)

RotateLeft rotates cell left

func (*Board) RotateRight

func (board *Board) RotateRight(x int, y int)

RotateRight rotates cell right

func (*Board) SetColor

func (board *Board) SetColor(x int, y int, color tcell.Color, rotation int)

SetColor sets the color and rotation of board location

func (*Board) StartLockDelayIfBottom

func (board *Board) StartLockDelayIfBottom() bool

StartLockDelayIfBottom if at bottom, starts lock delay

func (*Board) ValidBlockLocation

func (board *Board) ValidBlockLocation(x int, y int, mustBeOnBoard bool) bool

ValidBlockLocation checks if block location is vaild

type Boards

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

Boards holds all the boards

type BoardsJSON

type BoardsJSON struct {
	Name     string
	Mino     [][]string
	Rotation [][]int
}

BoardsJSON is for JSON format of boards

type Engine

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

Engine is the Tetirs game engine

func (*Engine) AddDeleteLines

func (engine *Engine) AddDeleteLines(lines int)

AddDeleteLines adds deleted lines to score

func (*Engine) AddScore

func (engine *Engine) AddScore(add int)

AddScore adds to score

func (*Engine) GameOver

func (engine *Engine) GameOver()

GameOver pauses engine and sets to game over

func (*Engine) LevelUp

func (engine *Engine) LevelUp()

LevelUp goes up a level

func (*Engine) NewGame

func (engine *Engine) NewGame()

NewGame resets board and starts a new game

func (*Engine) Pause

func (engine *Engine) Pause()

Pause the game

func (*Engine) PreviewBoard

func (engine *Engine) PreviewBoard()

PreviewBoard sets previewBoard to true

func (*Engine) ProcessEventKey

func (engine *Engine) ProcessEventKey(eventKey *tcell.EventKey)

ProcessEventKey process the key input event

func (*Engine) ResetTimer

func (engine *Engine) ResetTimer(duration time.Duration)

ResetTimer resets the time for lock delay or tick time

func (*Engine) Run

func (engine *Engine) Run()

Run runs the engine

func (*Engine) Start

func (engine *Engine) Start()

Start the game

func (*Engine) Stop

func (engine *Engine) Stop()

Stop the game

func (*Engine) UnPause

func (engine *Engine) UnPause()

UnPause the game

type EventEngineStopRun

type EventEngineStopRun struct {
	EventGame
}

EventEngineStopRun stop the run of the engine

type EventGame

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

EventGame is an game event

func (*EventGame) When

func (EventGame *EventGame) When() time.Time

When returns event when

type Mino

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

Mino is a mino

func NewMino

func NewMino() *Mino

NewMino creates a new Mino

func (*Mino) CloneMoveDown

func (mino *Mino) CloneMoveDown() *Mino

CloneMoveDown creates copy of the mino and moves it down

func (*Mino) CloneMoveLeft

func (mino *Mino) CloneMoveLeft() *Mino

CloneMoveLeft creates copy of the mino and moves it left

func (*Mino) CloneMoveRight

func (mino *Mino) CloneMoveRight() *Mino

CloneMoveRight creates copy of the mino and moves it right

func (*Mino) CloneRotateLeft

func (mino *Mino) CloneRotateLeft() *Mino

CloneRotateLeft creates copy of the mino and rotates it left

func (*Mino) CloneRotateRight

func (mino *Mino) CloneRotateRight() *Mino

CloneRotateRight creates copy of the mino and rotates it right

func (*Mino) DrawMino

func (mino *Mino) DrawMino(minoType MinoType)

DrawMino draws the mino on the board

func (*Mino) MoveDown

func (mino *Mino) MoveDown()

MoveDown moves the mino down

func (*Mino) MoveLeft

func (mino *Mino) MoveLeft()

MoveLeft moves the mino left

func (*Mino) MoveRight

func (mino *Mino) MoveRight()

MoveRight moves the mino right

func (*Mino) MoveUp

func (mino *Mino) MoveUp()

MoveUp moves the mino up

func (*Mino) RotateLeft

func (mino *Mino) RotateLeft()

RotateLeft rotates the mino left

func (*Mino) RotateRight

func (mino *Mino) RotateRight()

RotateRight rotates the mino right

func (*Mino) SetOnBoard

func (mino *Mino) SetOnBoard()

SetOnBoard attaches mino to the board

func (*Mino) ValidLocation

func (mino *Mino) ValidLocation(mustBeOnBoard bool) bool

ValidLocation check if the mino is in a valid location

type MinoBlocks

type MinoBlocks [][]tcell.Color

MinoBlocks is the blocks of the mino

type MinoRotation

type MinoRotation [4]MinoBlocks

MinoRotation is the rotation of the mino

type MinoType

type MinoType int

MinoType is the type of mino

const (

	// MinoPreview is for the preview mino
	MinoPreview MinoType = iota
	// MinoCurrent is for the current mino
	MinoCurrent = iota
)

type Minos

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

Minos is a bag of minos

type Ranking

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

Ranking holds the ranking scores

func NewRanking

func NewRanking() *Ranking

NewRanking create a new ranking

func (*Ranking) InsertScore

func (ranking *Ranking) InsertScore(newScore uint64)

InsertScore inserts a score into the rankings

func (*Ranking) Save

func (ranking *Ranking) Save()

Save saves the rankings to a file

type Settings

type Settings struct {
	Boards []BoardsJSON
}

Settings is the JSON load/save file

type View

type View struct {
}

View is the display engine

func (*View) DrawBlock

func (view *View) DrawBlock(x int, y int, color tcell.Color, rotation int)

DrawBlock draws a block

func (*View) DrawCursor

func (view *View) DrawCursor(x int, y int, color tcell.Color)

DrawCursor draws current cursor location

func (*View) DrawPreviewMinoBlock

func (view *View) DrawPreviewMinoBlock(x int, y int, color tcell.Color, rotation int, length int)

DrawPreviewMinoBlock draws the preview mino

func (*View) RefreshScreen

func (view *View) RefreshScreen()

RefreshScreen refreshes the updated view to the screen

func (*View) ShowDeleteAnimation

func (view *View) ShowDeleteAnimation(lines []int)

ShowDeleteAnimation draws the delete animation

func (*View) ShowGameOverAnimation

func (view *View) ShowGameOverAnimation()

ShowGameOverAnimation draws one randomily picked gave over animation

func (*View) Stop

func (view *View) Stop()

Stop stops the view

Jump to

Keyboard shortcuts

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