-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathruin.go
115 lines (98 loc) · 3.01 KB
/
ruin.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
package main
import "log"
// A ruin contains generation for Star Ruins & Space Hulks
type ruin struct {
ruinType, aesthetic, purpose, danger, depth, threat string
treasure treasure
}
// generate generates a ruin
func (r *ruin) generate() ruin {
r.ruinType = generateRuinType()
r.aesthetic = generateAesthetic()
r.purpose = generatePurpose()
r.danger = generateDanger()
r.depth = generateDepth()
r.threat = generateThreat()
r.treasure.generate()
return *r
}
// render renders the ruin to the game log.
func (r *ruin) render(req string) {
switch req {
case "type":
renderOutput(r.ruinType, "", "clear")
case "aesthetic":
renderOutput(r.aesthetic, "", "clear")
case "purpose":
renderOutput(r.purpose, "", "clear")
case "danger":
renderOutput(r.danger, "", "clear")
case "depth":
renderOutput(r.depth, "", "clear")
case "threat":
renderOutput(r.threat, "", "clear")
case "treasure":
r.treasure.render("notitle")
default:
renderOutput("Star Ruin", "h1", "purple")
renderOutput("Type: "+r.ruinType, "", "clear")
renderOutput("Aesthetic: "+r.aesthetic, "", "clear")
renderOutput("Purpose: "+r.purpose, "", "clear")
renderOutput("Danger Level: "+r.danger, "", "clear")
renderOutput("Depth: "+r.depth, "", "clear")
renderOutput("Threat: "+r.threat, "", "clear")
//r.treasure.render("notitle")
renderOutput("Treasure: "+r.treasure.aspect+" "+r.treasure.feature+" "+r.treasure.form, "", "magenta")
}
}
// generateRuinType returns a string containing a ruin type value.
func generateRuinType() string {
types, err := readNameFile("./data/ruins/type.names")
if err != nil {
log.Fatalf("readLines: %s", err)
}
return types[generateNumber(0, len(types)-1)]
}
// generateAesthetic returns a string containing a aesthetic value.
func generateAesthetic() string {
aesthetics, err := readNameFile("./data/ruins/aesthetic.names")
if err != nil {
log.Fatalf("readLines: %s", err)
}
return aesthetics[generateNumber(0, len(aesthetics)-1)]
}
// generatePurpose returns a string containing a purpose value.
func generatePurpose() string {
purposes, err := readNameFile("./data/ruins/purpose.names")
if err != nil {
log.Fatalf("readLines: %s", err)
}
return purposes[generateNumber(0, len(purposes)-1)]
}
// generateDanger returns a string containing a danger value.
func generateDanger() string {
danger := generateNumber(1, 20)
if danger < 10 {
return "Milk Run (5)"
} else if danger < 15 {
return "Perilous (10)"
} else {
return "Death Trap (15)"
}
}
// generateDepth returns a string containing a depth value.
func generateDepth() string {
depths, err := readNameFile("./data/ruins/depth.names")
if err != nil {
log.Fatalf("readLines: %s", err)
}
return depths[generateNumber(0, len(depths)-1)]
}
// generateThreat returns a string containing a threat value.
func generateThreat() string {
threats, err := readNameFile("./data/ruins/threat.names")
if err != nil {
log.Fatalf("readLines: %s", err)
}
return threats[generateNumber(0, len(threats)-1)]
}