From 3bd8fcd49d2eb53278472a8d47b488ebfeba175c Mon Sep 17 00:00:00 2001 From: Logen Kain Date: Mon, 9 Oct 2017 02:12:28 -0700 Subject: [PATCH] Changed seed to nano; added mainloop --- main.go | 43 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index d3e0599..bf593f5 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,8 @@ package main import ( + "bufio" + "fmt" "math/rand" "os" "os/exec" @@ -9,11 +11,36 @@ import ( func main() { initGame() - Battle(player, goblin) + 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) + } else if answer == "q" { + ClearScreen() + print("Ta!\n") + break + } else { + print("Try again, \n") + time.Sleep(time.Second) + ClearScreen() + } + + } } func initGame() { - rand.Seed(time.Now().Unix()) + rand.Seed(time.Now().UnixNano()) ClearScreen() } @@ -22,3 +49,15 @@ func ClearScreen() { cmd.Stdout = os.Stdout 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 +}