-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathgame.go
More file actions
72 lines (63 loc) · 1.63 KB
/
Copy pathgame.go
File metadata and controls
72 lines (63 loc) · 1.63 KB
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
package main
import (
"os"
"path/filepath"
"github.com/Sirupsen/logrus"
"github.com/anthonybishopric/pandemic-nerd-hurd/pandemic"
"gopkg.in/alecthomas/kingpin.v2"
)
var (
app = kingpin.New("pandemic–nerd-hurd", "Start a nerd herd game")
startCmd = app.Command("start", "Start a new game")
startNewGameFile = startCmd.Flag("new-game-file", "The file containing initial data about Cities, Players and Funded Events.").Default("data/new_game.json").ExistingFile()
startMonth = startCmd.Flag("month", "The name of the month in the game we are playing. If playing the second time in a month, add '2' after the name").Required().Enum(
"jan",
"feb",
"mar",
"apr",
"may",
"jun",
"jul",
"aug",
"sep",
"oct",
"nov",
"dec",
"jan2",
"feb2",
"mar2",
"apr2",
"may2",
"jun2",
"jul2",
"aug2",
"sep2",
"oct2",
"nov2",
"dec2",
)
loadCmd = app.Command("load", "Load a game from an existing saved game")
loadFile = loadCmd.Flag("file", "The JSON file containing the game state").Required().ExistingFile()
)
func main() {
cmd := kingpin.MustParse(app.Parse(os.Args[1:]))
logger := logrus.New()
fd, err := os.OpenFile("log.txt", os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0644)
logger.Out = fd
wd, _ := os.Getwd()
var gameState *pandemic.GameState
switch cmd {
case "start":
gameState, err = pandemic.NewGame(filepath.Join(wd, *startNewGameFile), *startMonth)
if err != nil {
logger.Fatalln(err)
}
case "load":
gameState, err = pandemic.LoadGame(filepath.Join(wd, *loadFile))
if err != nil {
logger.Fatalln(err)
}
}
view := NewView(logger)
view.Start(gameState)
}