Changed seed to nano; added mainloop

This commit is contained in:
Logen Kain 2017-10-09 02:12:28 -07:00
parent d9460a7c59
commit 3bd8fcd49d

41
main.go
View File

@ -1,6 +1,8 @@
package main package main
import ( import (
"bufio"
"fmt"
"math/rand" "math/rand"
"os" "os"
"os/exec" "os/exec"
@ -9,11 +11,36 @@ import (
func main() { func main() {
initGame() initGame()
var answer string
for {
print("Type 'q' to quit\n")
answer, _ = input("Would you like to fight a goblin? y/n ")
if answer == "n" {
print("What a pussy! \n")
time.Sleep(time.Second)
ClearScreen()
} else if answer == "y" {
print("Sweeeeeet! \n")
time.Sleep(time.Second)
ClearScreen()
Battle(player, goblin) Battle(player, goblin)
} else if answer == "q" {
ClearScreen()
print("Ta!\n")
break
} else {
print("Try again, \n")
time.Sleep(time.Second)
ClearScreen()
}
}
} }
func initGame() { func initGame() {
rand.Seed(time.Now().Unix()) rand.Seed(time.Now().UnixNano())
ClearScreen() ClearScreen()
} }
@ -22,3 +49,15 @@ func ClearScreen() {
cmd.Stdout = os.Stdout cmd.Stdout = os.Stdout
cmd.Run() cmd.Run()
} }
func input(s string) (string, error) {
stdin_buf := bufio.NewReader(os.Stdin)
fmt.Print(s)
text, err := stdin_buf.ReadString('\n')
if err != nil {
panic(err)
}
return text[:len(text)-1], err
}