-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
85 lines (63 loc) · 1.69 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
package main
import (
"bufio"
"embed"
"flag"
"fmt"
"log"
"os"
"strconv"
"strings"
)
//go:embed data/*.json
var content embed.FS
func main() {
var helpFlag bool
var challengeFlag bool
flag.BoolVar(&helpFlag, "help", false, "Display help information")
flag.BoolVar(&helpFlag, "h", false, "Display help information")
flag.BoolVar(&challengeFlag, "challenge", false, "Challenge mode with over 1000 most common words")
flag.BoolVar(&challengeFlag, "c", false, "Challenge mode with over 1000 most common words")
flag.Parse()
if len(flag.Args()) > 1 {
fmt.Println("Can't have more than one argument. Exiting...")
os.Exit(1)
}
if helpFlag {
fmt.Println("Usage: german [--challenge | -c] | [--help | -h] | [no arguments]")
fmt.Println("Options:")
flag.PrintDefaults()
os.Exit(0)
}
scanner := bufio.NewScanner(os.Stdin)
if !challengeFlag {
fmt.Println("Would you like to take on the Challenge Mode (Y/N)? (Default: N)")
scanner.Scan()
challengeFlag = strings.ToLower(scanner.Text()) == "y"
}
fmt.Println("How many would you like to try out? (default: 10)")
scanner.Scan()
numWords, err := strconv.Atoi(scanner.Text())
if err != nil {
fmt.Print("Defaulting to 10\n\n")
numWords = 10
}
correct := 0
var file []byte
if challengeFlag {
file, err = content.ReadFile("data/Top1000.json")
} else {
file, err = content.ReadFile("data/KnownWords.json")
}
if err != nil {
log.Fatal(err)
os.Exit(1)
}
words, err := UnmarshalWords(file)
if err != nil {
log.Fatal(err)
os.Exit(1)
}
PlayQuiz(words, scanner, numWords, &correct)
fmt.Println(string(colorGreen), "\nYou Got: "+strconv.Itoa(correct)+" Correct "+"Out of "+strconv.Itoa(numWords), string(colorReset))
}