go-tetris/globals.go

168 lines
3.0 KiB
Go
Raw Permalink Normal View History

package main
import (
2018-06-01 10:16:36 -05:00
"log"
"time"
2019-12-01 15:03:27 -06:00
"github.com/gdamore/tcell"
)
const (
2019-01-09 20:30:45 -06:00
boardXOffset = 4
boardYOffset = 2
aiTickDivider = 8
rankingFileName = "/go-tetris.db"
settingsFileName = "/go-tetris.json"
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
2019-12-01 15:03:27 -06:00
colorBlank = tcell.ColorBlack
colorCyan = tcell.ColorAqua // I
colorBlue = tcell.ColorBlue // J
colorWhite = tcell.ColorWhite // L
colorYellow = tcell.ColorYellow // O
colorGreen = tcell.ColorLime // S
colorMagenta = tcell.ColorFuchsia // T
colorRed = tcell.ColorRed // Z
engineModeRun engineMode = iota
engineModeRunWithAI
engineModeStopped
engineModeGameOver
engineModePaused
engineModePreview
engineModeEdit
)
type (
2019-12-01 15:03:27 -06:00
engineMode int
2018-10-02 20:21:08 -05:00
// MinoType is the type of mino
MinoType int
// MinoBlocks is the blocks of the mino
2019-12-01 15:03:27 -06:00
MinoBlocks [][]tcell.Color
2018-10-02 20:21:08 -05:00
// 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
2019-12-01 15:03:27 -06:00
colors [][]tcell.Color
rotation [][]int
previewMino *Mino
currentMino *Mino
dropDistance int
2019-01-11 20:39:41 -06:00
fullLinesY []bool
}
2019-01-09 20:30:45 -06:00
// Boards holds all the boards
Boards struct {
2019-01-09 20:30:45 -06:00
name string
2019-12-01 15:03:27 -06:00
colors [][]tcell.Color
rotation [][]int
}
2019-01-09 20:30:45 -06:00
// BoardsJSON is for JSON format of boards
BoardsJSON struct {
Name string
Mino [][]string
Rotation [][]int
}
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{}
2019-12-01 15:03:27 -06:00
chanEventKey chan *tcell.EventKey
ranking *Ranking
timer *time.Timer
tickTime time.Duration
2019-12-01 15:03:27 -06:00
mode engineMode
score int
level int
deleteLines int
ai *Ai
aiEnabled bool
aiTimer *time.Timer
2019-01-09 20:30:45 -06:00
}
// Edit is the board edit mode
Edit struct {
x int
y int
moved bool
boardSize bool
width int
height int
saved bool
}
// Settings is the JSON load/save file
Settings struct {
Boards []BoardsJSON
}
2019-12-01 15:03:27 -06:00
// EventGame is an game event
EventGame struct {
when time.Time
}
)
2019-12-01 15:03:27 -06:00
// When returns event when
func (EventGame *EventGame) When() time.Time {
return EventGame.when
}
var (
baseDir string
2018-06-01 10:16:36 -05:00
logger *log.Logger
2019-12-01 15:03:27 -06:00
screen tcell.Screen
minos *Minos
board *Board
view *View
engine *Engine
2019-01-09 20:30:45 -06:00
edit *Edit
boards []Boards
numInternalBoards int
)