trinket/main.go
2018-07-06 04:23:22 -07:00

65 lines
1009 B
Go

package main
import (
"bufio"
"fmt"
"math/rand"
"os"
"os/exec"
"time"
)
func main() {
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)
} 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().UnixNano())
ClearScreen()
}
//ClearScreen clear all output on screen
func ClearScreen() {
cmd := exec.Command("clear")
cmd.Stdout = os.Stdout
cmd.Run()
}
func input(s string) (string, error) {
stdinBuf := bufio.NewReader(os.Stdin)
fmt.Print(s)
text, err := stdinBuf.ReadString('\n')
if err != nil {
panic(err)
}
return text[:len(text)-1], err
}