go-tetris/globals.go

119 lines
2.0 KiB
Go
Raw Normal View History

package main
import (
2018-06-01 10:16:36 -05:00
"log"
"time"
"github.com/nsf/termbox-go"
)
const (
blankColor = termbox.ColorBlack
boardXOffset = 4
boardYOffset = 2
rankingFileName = "/tetris.db"
2018-10-02 20:21:08 -05:00
// MinoPreview is for the preview mino
MinoPreview MinoType = iota
2018-10-02 20:21:08 -05:00
// MinoCurrent is for the current mino
MinoCurrent = iota
// MinoDrop is for the drop mino
MinoDrop = iota
)
type (
2018-10-02 20:21:08 -05:00
// MinoType is the type of mino
MinoType int
// MinoBlocks is the blocks of the mino
MinoBlocks [][]termbox.Attribute
// MinoRotation is the rotation of the mino
MinoRotation [4]MinoBlocks
2018-10-02 20:21:08 -05:00
// Mino is a mino
Mino struct {
x int
y int
length int
rotation int
minoRotation MinoRotation
}
2018-10-02 20:21:08 -05:00
// Minos is a bag of minos
Minos struct {
minoBag [7]MinoRotation
bagRand []int
bagIndex int
}
2018-10-02 20:21:08 -05:00
// Board is the Tetris board
Board struct {
boardsIndex int
width int
height int
colors [][]termbox.Attribute
rotation [][]int
previewMino *Mino
currentMino *Mino
dropDistance int
}
2018-10-02 20:21:08 -05:00
// Boards holds all the premade boards
Boards struct {
colors [][]termbox.Attribute
rotation [][]int
}
2018-10-02 20:21:08 -05:00
// KeyInput is the key input engine
KeyInput struct {
stopped bool
chanStop chan struct{}
chanKeyInput chan *termbox.Event
}
2018-10-02 20:21:08 -05:00
// View is the display engine
View struct {
}
2018-10-02 20:21:08 -05:00
// Ai is the AI engine
Ai struct {
queue *[]rune
newQueue *[]rune
index int
}
2018-10-02 20:21:08 -05:00
// Ranking holds the ranking scores
Ranking struct {
scores []uint64
}
2018-10-02 20:21:08 -05:00
// Engine is the Tetirs game engine
Engine struct {
stopped bool
chanStop chan struct{}
keyInput *KeyInput
ranking *Ranking
timer *time.Timer
tickTime time.Duration
paused bool
gameOver bool
previewBoard bool
score int
level int
deleteLines int
ai *Ai
aiEnabled bool
aiTimer *time.Timer
}
)
var (
boards []Boards
baseDir string
2018-06-01 10:16:36 -05:00
logger *log.Logger
minos *Minos
board *Board
view *View
engine *Engine
)