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
/
Copy pathminos.go
104 lines (96 loc) · 3.03 KB
/
minos.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
package main
import (
"math/rand"
"github.com/gdamore/tcell"
)
// NewMinos creates the minos and minoBag
func NewMinos() {
minoI := MinoBlocks{
[]tcell.Color{colorBlank, colorCyan, colorBlank, colorBlank},
[]tcell.Color{colorBlank, colorCyan, colorBlank, colorBlank},
[]tcell.Color{colorBlank, colorCyan, colorBlank, colorBlank},
[]tcell.Color{colorBlank, colorCyan, colorBlank, colorBlank},
}
minoJ := MinoBlocks{
[]tcell.Color{colorBlue, colorBlue, colorBlank},
[]tcell.Color{colorBlank, colorBlue, colorBlank},
[]tcell.Color{colorBlank, colorBlue, colorBlank},
}
minoL := MinoBlocks{
[]tcell.Color{colorBlank, colorWhite, colorBlank},
[]tcell.Color{colorBlank, colorWhite, colorBlank},
[]tcell.Color{colorWhite, colorWhite, colorBlank},
}
minoO := MinoBlocks{
[]tcell.Color{colorYellow, colorYellow},
[]tcell.Color{colorYellow, colorYellow},
}
minoS := MinoBlocks{
[]tcell.Color{colorBlank, colorGreen, colorBlank},
[]tcell.Color{colorGreen, colorGreen, colorBlank},
[]tcell.Color{colorGreen, colorBlank, colorBlank},
}
minoT := MinoBlocks{
[]tcell.Color{colorBlank, colorMagenta, colorBlank},
[]tcell.Color{colorMagenta, colorMagenta, colorBlank},
[]tcell.Color{colorBlank, colorMagenta, colorBlank},
}
minoZ := MinoBlocks{
[]tcell.Color{colorRed, colorBlank, colorBlank},
[]tcell.Color{colorRed, colorRed, colorBlank},
[]tcell.Color{colorBlank, colorRed, colorBlank},
}
var minoRotationI MinoRotation
minoRotationI[0] = minoI
for i := 1; i < 4; i++ {
minoRotationI[i] = minosCloneRotateRight(minoRotationI[i-1])
}
var minoRotationJ MinoRotation
minoRotationJ[0] = minoJ
for i := 1; i < 4; i++ {
minoRotationJ[i] = minosCloneRotateRight(minoRotationJ[i-1])
}
var minoRotationL MinoRotation
minoRotationL[0] = minoL
for i := 1; i < 4; i++ {
minoRotationL[i] = minosCloneRotateRight(minoRotationL[i-1])
}
var minoRotationO MinoRotation
minoRotationO[0] = minoO
minoRotationO[1] = minoO
minoRotationO[2] = minoO
minoRotationO[3] = minoO
var minoRotationS MinoRotation
minoRotationS[0] = minoS
for i := 1; i < 4; i++ {
minoRotationS[i] = minosCloneRotateRight(minoRotationS[i-1])
}
var minoRotationT MinoRotation
minoRotationT[0] = minoT
for i := 1; i < 4; i++ {
minoRotationT[i] = minosCloneRotateRight(minoRotationT[i-1])
}
var minoRotationZ MinoRotation
minoRotationZ[0] = minoZ
for i := 1; i < 4; i++ {
minoRotationZ[i] = minosCloneRotateRight(minoRotationZ[i-1])
}
minos = &Minos{
minoBag: [7]MinoRotation{minoRotationI, minoRotationJ, minoRotationL, minoRotationO, minoRotationS, minoRotationT, minoRotationZ},
bagRand: rand.Perm(7),
}
}
// minosCloneRotateRight clones a mino and rotates the mino to the right
func minosCloneRotateRight(minoBlocks MinoBlocks) MinoBlocks {
length := len(minoBlocks)
newMinoBlocks := make(MinoBlocks, length, length)
for i := 0; i < length; i++ {
newMinoBlocks[i] = make([]tcell.Color, length, length)
}
for i := 0; i < length; i++ {
for j := 0; j < length; j++ {
newMinoBlocks[length-j-1][i] = minoBlocks[i][j]
}
}
return newMinoBlocks
}