diff --git a/golangr/file-reader/main.go b/golangr/file-reader/main.go index 03475fd..6452181 100644 --- a/golangr/file-reader/main.go +++ b/golangr/file-reader/main.go @@ -7,6 +7,7 @@ import ( "os" "strconv" "strings" + "time" //"strconv" ) @@ -15,6 +16,10 @@ type PlayerStats struct { lives uint8 } +func clear() { + fmt.Print("\033[H\033[2J") +} + var player PlayerStats var names = []string{} var err error @@ -35,12 +40,14 @@ func main() { os.Exit(1) } - fmt.Printf("Welcome to the hanged man game!\nMay I know your name?\nName: ") - // _, err = fmt.Scanln(&player.name) - // catchErr(err) - player.name = scanLine() - for { + clear() + + fmt.Printf("Welcome to the hanged man game!\nMay I know your name?\nName: ") + // _, err = fmt.Scanln(&player.name) + // catchErr(err) + player.name = scanLine() + fmt.Printf("How many lives would you like to have?\nLives: ") stringLives := scanLine() //TODO: fix this garbage @@ -48,33 +55,44 @@ func main() { catchErr(err) player.lives = uint8(intLives) + clear() fmt.Printf("Name: %v\n", player.name) fmt.Printf("Lives: %v\n", player.lives) - fmt.Printf("Proceed? [y/n] ") + fmt.Printf("Is this correct? [y/n] ") var choice string _, err = fmt.Scanln(&choice) catchErr(err) if choice == "y" { - break + game() } } - filePath := os.Args[1] - randWord := getWord(filePath) - - fmt.Printf("The chosen name is %v\n", randWord) - // fmt.Scan(&guess) - fmt.Scanln(&guessLetter) - // if guess == randWord { - // fmt.Printf("You win!\n") - // } else { - // fmt.Printf("You lose!\n") - // } + // filePath := os.Args[1] + // randWord := getWord(filePath) + // + // fmt.Printf("The chosen name is %v\n", randWord) + // fmt.Scanln(&guessLetter) } -func letterCheck(char rune) { +func gameStatus() { + clear() + fmt.Println("Player:", player.name) + fmt.Println("Lives:", player.lives) +} + +func game() { + clear() + for { + gameStatus() + if player.lives == 0 { + fmt.Println("You lose!") + os.Exit(1) + } + time.Sleep(2 * time.Second) + player.lives-- + } } func catchErr(err error) {