forked from p4tin/GoTextAdv
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
67 lines (55 loc) · 1.03 KB
/
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"fmt"
"os"
"math/rand"
"time"
"bufio"
"github.com/fatih/color"
)
var Out *os.File
var In *os.File
var player Character
func init() {
rand.Seed(time.Now().UTC().UnixNano())
Out = os.Stdout
In = os.Stdin
}
func main() {
player = *new(Character)
player.Name = "Paul"
player.Speed = 1 + rand.Intn(100)
player.Health = 100
player.Alive = true
player.Weap = 1
player.CurrentLocation = "Bridge"
player.Play()
}
func Outputf(c string, format string, args ...interface{}) {
s := fmt.Sprintf(format, args...)
Output(c, s)
}
func Output(c string, args ...interface{}) {
s := fmt.Sprint(args...)
col := color.WhiteString
switch(c) {
case "green":
col = color.GreenString
case "red":
col = color.RedString
case "blue":
col = color.BlueString
case "yellow":
col = color.YellowString
}
fmt.Fprintln(Out, col(s))
}
func UserInput(i *int) {
fmt.Fscan(In, i)
}
func UserInputln() string {
reader := bufio.NewReader(os.Stdin)
fmt.Print("\n >>> ")
text, _ := reader.ReadString('\n')
return text
}