-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
165 lines (124 loc) · 4.02 KB
/
main.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
package main
import (
"bufio"
"fmt"
"os"
"os/exec"
"runtime"
"strconv"
"strings"
"github.com/ImS0L0/GoRubikCube/Color"
"github.com/ImS0L0/GoRubikCube/Cube"
)
func clearTerminal() {
var Terminal *exec.Cmd
if runtime.GOOS == "windows" {
Terminal = exec.Command("cmd", "/c", "cls")
} else {
Terminal = exec.Command("clear")
}
Terminal.Stdout = os.Stdout
Terminal.Run()
fmt.Println()
}
func askQuestionY(s *bufio.Scanner, yes, no func()) {
s.Scan()
input := s.Text()
if input == "" || strings.ToLower(input) == "y" {
yes()
} else {
no()
}
}
func main() {
scanner := bufio.NewScanner(os.Stdin)
var cube Cube.Cube
msg := ""
for {
clearTerminal()
fmt.Printf(Color.Yellow, "WELCOME!!\n\n")
fmt.Printf(Color.White, "Enter Cube size 2 to 10")
fmt.Printf(Color.Blue, " (or 25, it depend of a terminal size)")
fmt.Printf(Color.Red, " (type \"exit\" to leave)")
fmt.Printf(Color.Red, msg)
fmt.Printf(Color.Blue, "\n ƒ: ")
scanner.Scan()
input := scanner.Text()
if strings.ToLower(input) == "exit" {
fmt.Printf(Color.Yellow, "\n\n Good Bye ;)\n\n")
break
}
if num, err := strconv.Atoi(input); err != nil {
msg = " (\"" + input + "\" is not a number)"
continue
} else {
cube.New(uint8(num))
clearTerminal()
cube.PrintCube()
fmt.Printf(Color.White, "\nScramble Cube? (Y/n)")
fmt.Printf(Color.Blue, "\n ƒ: ")
askQuestionY(scanner, func() {
clearTerminal()
cube.PrintCube()
fmt.Printf(Color.White, "\nScramble Size Automatic? (Y/n)")
fmt.Printf(Color.Blue, "\n ƒ: ")
askQuestionY(scanner, func() {
cube.AutoScramble()
}, func() {
msg = ""
for {
clearTerminal()
cube.PrintCube()
fmt.Printf(Color.White, "\nEnter Size")
fmt.Printf(Color.Red, msg)
fmt.Printf(Color.Blue, "\n ƒ: ")
scanner.Scan()
input = scanner.Text()
if num, err = strconv.Atoi(input); err != nil {
msg = " (\"" + input + "\" is not a number)"
continue
} else {
cube.CreateScramble(uint8(num))
break
}
}
})
}, func() {})
for {
clearTerminal()
if len(cube.GetScramble()) > 0 {
fmt.Printf(Color.Blue, "\n Scramble: ")
fmt.Printf(Color.Green, cube.GetScramble())
fmt.Println()
}
cube.PrintCube()
fmt.Printf(Color.White, "\nEnter Movements")
fmt.Printf(Color.Red, " (type \"exit\" to leave of Cube)")
fmt.Printf(Color.Orange, " (type \"help\" for show the help)")
fmt.Printf(Color.Blue, "\n ƒ: ")
scanner.Scan()
input = scanner.Text()
inputLowerCase := strings.ToLower(input)
if inputLowerCase == "exit" {
break
} else if inputLowerCase == "help" {
clearTerminal()
fmt.Printf(Color.White, "Notation:\n\n")
fmt.Printf(Color.White, "All notations usually have a capital letter (example: U, D, R, L ...) and each letter represents a movement:\n\n")
fmt.Printf(Color.Green, "\tU = Up layer\n\tD = Down layer\n\tR = Right layer\n\tL = Left layer\n\tF = Front layer\n\tB = Back layer\n\n")
fmt.Printf(Color.White, "Too exist middle movements\n\n")
fmt.Printf(Color.Green, "\tE = between U and D (E follows D)\n\tM = between L and R (M follows L)\n\tS = between F and B (S follows F)\n\n")
fmt.Printf(Color.White, "All this movements can move clockwise and counterclockwise, represented by a simple quotation mark, like this: U' F' L' ...\n\n")
fmt.Printf(Color.White, "To this movements are called \"prime\" (or opposide) movements example: U' is U prime.\n\n")
fmt.Printf(Color.White, "The \"prime\" movements are like the nomal movement, but on the contrary, namely, if U movement moves to the left, U Prime moves to the right.\n\n")
fmt.Printf(Color.White, "And finally, the \"twice\" movements is like a normal movement but this be repeat 2 times, and this is representated like this U2 or F2 or R2 ...\n\n\n")
fmt.Printf(Color.Green, " (Enter to quit) ")
scanner.Scan()
} else {
arr := strings.Split(input, " ")
cube.MoveCube(&arr)
}
}
}
}
}