-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmech.go
58 lines (49 loc) · 1.38 KB
/
mech.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
package main
import (
"log"
"strconv"
)
// A mech contains generation for Mighty Mechs
type mech struct {
weapon, system string
}
// generate generate a mech.
func (m *mech) generate() mech {
m.weapon = generateMechWeapon()
m.system = generateMechSystem()
return *m
}
// render renders the mech to the game log.
func (m *mech) render(req string) {
switch req {
case "weapon":
renderOutput(m.weapon, "", "clear")
case "system":
renderOutput(m.system, "", "clear")
case "notitle":
renderOutput("Weapon: "+m.weapon, "", "clear")
renderOutput("System: "+m.system, "", "clear")
default:
renderOutput("Mech", "h1", "yellow")
renderOutput("Weapon: "+m.weapon, "", "clear")
renderOutput("System: "+m.system, "", "clear")
}
}
// generateMechWeapon returns a string containing a mech weapon value.
func generateMechWeapon() string {
rnd := generateNumber(1, 3)
weapons, err := readNameFile("./data/mechs/weapon0" + strconv.Itoa(rnd) + ".names")
if err != nil {
log.Fatalf("readLines: %s", err)
}
return weapons[generateNumber(0, len(weapons)-1)]
}
// generateMechSystem returns a string containing a mech system value.
func generateMechSystem() string {
rnd := generateNumber(1, 6)
systems, err := readNameFile("./data/mechs/system0" + strconv.Itoa(rnd) + ".names")
if err != nil {
log.Fatalf("readLines: %s", err)
}
return systems[generateNumber(0, len(systems)-1)]
}