-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.go
139 lines (121 loc) · 2.32 KB
/
game.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
package main
import (
"bufio"
"fmt"
"math/rand"
"os"
"regexp"
"strings"
"github.com/evilsocket/islazy/log"
"github.com/manifoldco/promptui"
"github.com/moorada/lelouch/dictionary"
)
func gamePhraseWN() {
chooseLevelGame()
for {
if wn() == -1 {
return
}
}
}
func gameMix() {
chooseLevelGame()
for {
random := rand.Intn(2)
if random == 0 {
if wn() == -1 {
return
}
} else {
if nw() == -1 {
return
}
}
}
}
func wn() int {
l := getLevelGame(levelGame)
number := stringWithCharset(l, charsetNumber)
SS := numberToWordSet(number)
wordSet := SS[0]
if len(SS) > 1 {
randomWordSet := rand.Intn(len(SS) - 1)
wordSet = SS[randomWordSet]
}
phrase := ""
for _, ws := range wordSet {
wordSlice := strings.Split(ws, ",")
randomWord := 0
if len(wordSlice) > 1 {
randomWord = rand.Intn(len(wordSlice) - 1)
}
phrase = phrase + wordSlice[randomWord] + " "
}
fmt.Println("Converti le parole:", phrase)
var response string
scanner := bufio.NewScanner(os.Stdin)
if scanner.Scan() {
response = scanner.Text()
}
re := regexp.MustCompile("[^a-zA-Z0-9_]+")
response = re.ReplaceAllString(response, "")
if number == response {
fmt.Println("Corretto!")
} else {
fmt.Println("Sbagliato!! \nLa soluzione è: " + number)
}
prompt := promptui.Select{
Label: "Seleziona",
Items: []string{Continua, MenuPrincipale},
}
_, result, err := prompt.Run()
if err != nil {
log.Fatal("Error: %s", err)
}
switch result {
case MenuPrincipale:
return -1
default:
return 0
}
}
func gamePhraseNW() {
chooseLevelGame()
for {
if nw() == -1 {
return
}
}
}
func nw() int {
l := getLevelGame(levelGame)
number := stringWithCharset(l, charsetNumber)
fmt.Println("Converti il numero:", number)
var response string
scanner := bufio.NewScanner(os.Stdin)
if scanner.Scan() {
response = scanner.Text()
}
if dictionary.WordToNumber(response) == number {
fmt.Println("Corretto!")
} else {
fmt.Println("Sbagliato!!")
}
prompt := promptui.Select{
Label: "Seleziona",
Items: []string{Continua, MostraSoluzioni, MenuPrincipale},
}
_, result, err := prompt.Run()
if err != nil {
log.Fatal("Error: %s", err)
}
switch result {
case MostraSoluzioni:
showTableWordSet(dictionary.WordToNumber(number))
return 0
case MenuPrincipale:
return -1
default:
return 0
}
}