diff --git a/golangr/file-reader/main.go b/golangr/file-reader/main.go index 6452181..fd6c27d 100644 --- a/golangr/file-reader/main.go +++ b/golangr/file-reader/main.go @@ -8,6 +8,7 @@ import ( "strconv" "strings" "time" + //"time" //"strconv" ) @@ -68,8 +69,6 @@ func main() { } } - // filePath := os.Args[1] - // randWord := getWord(filePath) // // fmt.Printf("The chosen name is %v\n", randWord) // fmt.Scanln(&guessLetter) @@ -84,14 +83,25 @@ func gameStatus() { func game() { clear() + filePath := os.Args[1] + randWord := getWord(filePath) for { gameStatus() if player.lives == 0 { fmt.Println("You lose!") - os.Exit(1) + os.Exit(0) + } + fmt.Printf("Guess: ") + fmt.Scanln(&guess) + if guess == randWord { + fmt.Println("You win!") + os.Exit(0) + } else { + fmt.Println("Wrong!") + player.lives-- + time.Sleep(2 * time.Second) + clear() } - time.Sleep(2 * time.Second) - player.lives-- } }