This repository has been archived by the owner on Dec 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
globals.go
167 lines (144 loc) · 2.96 KB
/
globals.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
package main
import (
"log"
"time"
"github.com/gdamore/tcell"
)
const (
boardXOffset = 4
boardYOffset = 2
aiTickDivider = 8
rankingFileName = "/go-tetris.db"
settingsFileName = "/go-tetris.json"
// MinoPreview is for the preview mino
MinoPreview MinoType = iota
// MinoCurrent is for the current mino
MinoCurrent = iota
// MinoDrop is for the drop mino
MinoDrop = iota
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 (
engineMode int
// MinoType is the type of mino
MinoType int
// MinoBlocks is the blocks of the mino
MinoBlocks [][]tcell.Color
// MinoRotation is the rotation of the mino
MinoRotation [4]MinoBlocks
// Mino is a mino
Mino struct {
x int
y int
length int
rotation int
minoRotation MinoRotation
}
// Minos is a bag of minos
Minos struct {
minoBag [7]MinoRotation
bagRand []int
bagIndex int
}
// Board is the Tetris board
Board struct {
boardsIndex int
width int
height int
colors [][]tcell.Color
rotation [][]int
previewMino *Mino
currentMino *Mino
dropDistance int
fullLinesY []bool
}
// Boards holds all the boards
Boards struct {
name string
colors [][]tcell.Color
rotation [][]int
}
// BoardsJSON is for JSON format of boards
BoardsJSON struct {
Name string
Mino [][]string
Rotation [][]int
}
// View is the display engine
View struct {
}
// Ai is the AI engine
Ai struct {
queue *[]rune
newQueue *[]rune
index int
}
// Ranking holds the ranking scores
Ranking struct {
scores []uint64
}
// Engine is the Tetirs game engine
Engine struct {
stopped bool
chanStop chan struct{}
chanEventKey chan *tcell.EventKey
ranking *Ranking
timer *time.Timer
tickTime time.Duration
mode engineMode
score int
level int
deleteLines int
ai *Ai
aiEnabled bool
aiTimer *time.Timer
}
// 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
}
// EventGame is an game event
EventGame struct {
when time.Time
}
)
// When returns event when
func (EventGame *EventGame) When() time.Time {
return EventGame.when
}
var (
baseDir string
logger *log.Logger
screen tcell.Screen
minos *Minos
board *Board
view *View
engine *Engine
edit *Edit
boards []Boards
numInternalBoards int
)