From 01a822c9ab43ddb1ce4417bcd2bd2b78577a0f73 Mon Sep 17 00:00:00 2001 From: raul Date: Sat, 10 Feb 2024 22:20:19 +0100 Subject: [PATCH] Added the actual game --- golangr/file-reader/main.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) 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-- } }