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.
This commit is contained in:
raul 2024-02-23 07:37:28 +00:00
parent f93efc0986
commit 6656971e10
1 changed files with 3 additions and 22 deletions

25
main.go
View File

@ -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()