-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
43 lines (39 loc) · 777 Bytes
/
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
package main
import (
"fmt"
"math/rand"
"os"
"strconv"
"time"
"github.com/padawin/german-practice/game"
)
func main() {
rand.Seed(time.Now().Unix())
if len(os.Args) == 1 {
fmt.Println("Usage:")
for game_name, game_info := range game.Games() {
extra := ""
if game_info.Interactive {
extra = "number"
}
fmt.Printf("%s %s %s\n", os.Args[0], game_name, extra)
fmt.Printf("\t%s\n", game_info.Help)
}
return
}
game_name := os.Args[1]
if !game.IsValidGame(game_name) {
fmt.Println("Invalid game name")
return
}
n := 1
if game.IsInteractive(game_name) && len(os.Args) == 3 {
var err error
n, err = strconv.Atoi(os.Args[2])
if err != nil {
fmt.Println("Invalid number of iterations")
return
}
}
game.Play(game_name, n)
}