diff --git a/main.go b/main.go index ecec661..863a9d0 100644 --- a/main.go +++ b/main.go @@ -168,14 +168,34 @@ func alreadyCorrect(gs string) (isGuess bool) { return isAlreadyGuessed } +func isEmpty(guess string) (isEmpty bool) { + isEmpty = false + if guess == "" { + isEmpty = true + } + return isEmpty +} + func game() { for { gameStatus() checkLose() checkWin() - fmt.Printf("Guess: ") - fmt.Scanln(&guess) + checkEmpty: + for { + fmt.Printf("Guess: ") + fmt.Scanln(&guess) + + if isEmpty(guess) == false { + break checkEmpty + } else { + gameStatus() + } + + } + + // TODO: prevent players from inputting multiple characters, UTF-8 is gonna be a pain if getLetter(guess) == true { if alreadyCorrect(guess) == true { @@ -197,6 +217,9 @@ func game() { time.Sleep(1 * time.Second) } } + // Realized entering empty input would still cause "already guessed" errors + // because guess wasn't being reset + guess = "" } }