-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevent.go
84 lines (68 loc) · 2.12 KB
/
event.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
package main
import "log"
// An event contains generation for Episode Events
type event struct {
one, two string
}
// generate generates an event
func (e *event) generate(t int) event {
switch t {
case 1:
e.one, e.two = generateScuffleEvent()
case 2:
e.one, e.two = generateSocialEvent()
case 3:
e.one, e.two = generateEncounterEvent()
case 4:
e.one, e.two = generateDifficultyEvent()
}
return *e
}
// render renders the event to the game log.
func (e *event) render() {
renderOutput(e.one+" | "+e.two, "", "clear")
}
// generateScuffleEvent return two strings containing scuffle values.
func generateScuffleEvent() (string, string) {
scuffles, err := readNameFile("./data/events/scuffle.names")
if err != nil {
log.Fatalf("readLines: %s", err)
}
tactics, err := readNameFile("./data/events/tactic.names")
if err != nil {
log.Fatalf("readLines: %s", err)
}
enemy := scuffles[generateNumber(0, len(scuffles)-1)]
tactic := tactics[generateNumber(0, len(tactics)-1)]
return enemy, tactic
}
// generateSocialEvent return two strings containing social values.
func generateSocialEvent() (string, string) {
socials, err := readNameFile("./data/events/social.names")
if err != nil {
log.Fatalf("readLines: %s", err)
}
bearings, err := readNameFile("./data/events/bearing.names")
if err != nil {
log.Fatalf("readLines: %s", err)
}
social := socials[generateNumber(0, len(socials)-1)]
bearing := bearings[generateNumber(0, len(bearings)-1)]
return social, bearing
}
// generateEncounterEvent return two strings containing encounter values.
func generateEncounterEvent() (string, string) {
encounters, err := readNameFile("./data/events/encounter.names")
if err != nil {
log.Fatalf("readLines: %s", err)
}
return encounters[generateNumber(0, len(encounters)-1)], generateFlavor()
}
// generateDifficultyEvent return two strings containing difficulty values.
func generateDifficultyEvent() (string, string) {
difficulties, err := readNameFile("./data/events/difficulty.names")
if err != nil {
log.Fatalf("readLines: %s", err)
}
return difficulties[generateNumber(0, len(difficulties)-1)], generateFlavor()
}