-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
78 lines (67 loc) · 1.31 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
67
68
69
70
71
72
73
74
75
76
77
78
package main
import (
"bufio"
"fmt"
"github.com/fatih/color"
"math/rand"
"os"
"time"
)
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 setPlayerInfo() Character {
player = *new(Character)
Output("cyan", "Hello user, what is your name?")
name := UserInputln()
player.Name = name
player.Speed = 1 + rand.Intn(100)
player.Alive = true
player.Weap = 1
player.CurrentLocation = "Room"
player.Health = 100
Output("cyan", "Good luck my friend!")
return player
}
func main() {
player = setPlayerInfo()
// setUpDB(player)
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
case "magenta":
col = color.MagentaString
case "cyan":
col = color.CyanString
}
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
}