-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlevel-init.go
More file actions
90 lines (81 loc) · 2.1 KB
/
level-init.go
File metadata and controls
90 lines (81 loc) · 2.1 KB
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
package main
import "github.com/gdamore/tcell/v2"
// 45x23
func drawInitScreen(scr tcell.Screen, force bool) {
scr.Fill(0, DEF_SF)
if term_width < 45 || term_height < 23 {
is_term_too_small = true
printYourTermIsTooSmall(scr, 45, 23)
} else {
is_term_too_small = false
centerX, centerY := (term_width-45)/2, (term_height-23)/2
printHeader(scr, centerX, centerY)
printBoxInitChoose(scr)
printInitInstruction(scr)
}
if force {
scr.Sync()
} else {
scr.Show()
}
}
func printBoxInitChoose(scr tcell.Screen) {
x, y := (term_width-45)/2, (term_height-23)/2
printBox(scr, x+3, y+8, 9*2, 9, DEF_SF, is_select_level)
printText(scr, x+3+7, y+8, 5, 1, DEF_SF.Bold(is_select_level), "LEVEL")
printNumber(scr, x+3+6, y+8+2, cur_level)
printBox(scr, x+3+9*2+3, y+8, 9*2, 9, DEF_SF, !is_select_level)
printText(scr, x+3+9*2+3+6, y+8, 6, 1, DEF_SF.Bold(!is_select_level), "HEIGHT")
printNumber(scr, x+3+9*2+3+6, y+8+2, cur_height)
}
func printInitInstruction(scr tcell.Screen) {
x, y := (term_width-45)/2, (term_height-23)/2
printBox(scr, x+8, y+19, 28, 4, DEF_SF, false)
printText(scr, x+8+2, y+19+1, 24, 1, DEF_SF.Bold(true), "USE ARROW KEYS TO SELECT")
printText(scr, x+8+2+3, y+19+2, 18, 1, DEF_SF.Bold(true), "AND ENTER TO START")
}
func switchInitChoose() {
is_select_level = !is_select_level
}
func incInitChoose() {
if is_select_level {
cur_level++
if cur_level > MAX_TETRIS_LEVEL {
cur_level = MIN_TETRIS_LEVEL
}
} else {
cur_height++
if cur_height > MAX_TETRIS_HEIGHT {
cur_height = MIN_TETRIS_HEIGHT
}
}
}
func decInitChoose() {
if is_select_level {
cur_level--
if cur_level < MIN_TETRIS_LEVEL {
cur_level = MAX_TETRIS_LEVEL
}
} else {
cur_height--
if cur_height < MIN_TETRIS_HEIGHT {
cur_height = MAX_TETRIS_HEIGHT
}
}
}
func initTetrisSession(scr tcell.Screen) {
is_initialization = false
restartTetris()
drawTetrisScreen(scr, false)
go goDownPlease(scr)
}
func restartTetris() {
is_game_over = false
is_paused = false
is_can_hold = true
score = 0
hold_tetro.color = -1
cur_board.fillBlank()
cur_board.generateRandomBlock(cur_height * 2)
dropTetromino(-1)
}