trinket/main.go

65 lines
1009 B
Go
Raw Normal View History

2017-10-08 22:17:53 -07:00
package main
import (
2017-10-09 02:12:28 -07:00
"bufio"
"fmt"
"math/rand"
"os"
"os/exec"
"time"
)
2017-10-08 22:17:53 -07:00
2017-10-09 00:27:09 -07:00
func main() {
initGame()
2017-10-09 02:12:28 -07:00
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()
}
}
2017-10-09 00:27:09 -07:00
}
func initGame() {
2017-10-09 02:12:28 -07:00
rand.Seed(time.Now().UnixNano())
ClearScreen()
}
2018-07-06 04:23:22 -07:00
//ClearScreen clear all output on screen
func ClearScreen() {
cmd := exec.Command("clear")
cmd.Stdout = os.Stdout
cmd.Run()
}
2017-10-09 02:12:28 -07:00
func input(s string) (string, error) {
2018-07-06 04:23:22 -07:00
stdinBuf := bufio.NewReader(os.Stdin)
2017-10-09 02:12:28 -07:00
fmt.Print(s)
2018-07-06 04:23:22 -07:00
text, err := stdinBuf.ReadString('\n')
2017-10-09 02:12:28 -07:00
if err != nil {
panic(err)
}
return text[:len(text)-1], err
}