From 6656971e10af7248e6421c4522c0e18420999bec Mon Sep 17 00:00:00 2001 From: raul Date: Fri, 23 Feb 2024 07:37:28 +0000 Subject: [PATCH] Spaced guesses no longer pass sanity checks Players could input guesses such as "b FOOBAR" with the program still picking up the "b" character, any input with spaces in it will now be ignored. --- main.go | 25 +++---------------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/main.go b/main.go index 863a9d0..42e14ab 100644 --- a/main.go +++ b/main.go @@ -185,9 +185,10 @@ func game() { checkEmpty: for { fmt.Printf("Guess: ") - fmt.Scanln(&guess) + //fmt.Scanln(&guess) + guess = scanLine() - if isEmpty(guess) == false { + if isEmpty(guess) == false && len([]rune(guess)) == 1 { break checkEmpty } else { gameStatus() @@ -195,8 +196,6 @@ func game() { } - // TODO: prevent players from inputting multiple characters, UTF-8 is gonna be a pain - if getLetter(guess) == true { if alreadyCorrect(guess) == true { fmt.Printf("[-] You've already guessed this correct letter") @@ -250,24 +249,6 @@ func getWord(path string) (word string) { return randName } -// func setClear() { -// switch runtime.GOOS { -// case "linux": -// fmt.Println("You're using linux") -// time.Sleep(1 * time.Second) -// clearCommand = exec.Command("clear") -// clearCommand.Stdout = os.Stdout -// case "windows": -// fmt.Println("You're using windows") -// time.Sleep(1 * time.Second) -// clearCommand = exec.Command("cmd", "/c", "cls") -// clearCommand.Stdout = os.Stdout -// default: -// fmt.Println("Huh?") -// os.Exit(1) -// } -// } - func clear() { screen.Clear() screen.MoveTopLeft()