Added the actual game

This commit is contained in:
raul 2024-02-10 22:20:19 +01:00
parent d1fddbe7ee
commit 01a822c9ab
1 changed files with 15 additions and 5 deletions

View File

@ -8,6 +8,7 @@ import (
"strconv" "strconv"
"strings" "strings"
"time" "time"
//"time"
//"strconv" //"strconv"
) )
@ -68,8 +69,6 @@ func main() {
} }
} }
// filePath := os.Args[1]
// randWord := getWord(filePath)
// //
// fmt.Printf("The chosen name is %v\n", randWord) // fmt.Printf("The chosen name is %v\n", randWord)
// fmt.Scanln(&guessLetter) // fmt.Scanln(&guessLetter)
@ -84,14 +83,25 @@ func gameStatus() {
func game() { func game() {
clear() clear()
filePath := os.Args[1]
randWord := getWord(filePath)
for { for {
gameStatus() gameStatus()
if player.lives == 0 { if player.lives == 0 {
fmt.Println("You lose!") 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--
} }
} }