57 lines
1.1 KiB
Go
57 lines
1.1 KiB
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
func game() {
|
||
|
|
||
|
// TODO: Catch SIGINT so you can ask the user if he wants to quit or not
|
||
|
// TODO: Do not do what I said above, I have to first learn how goroutines actually work
|
||
|
|
||
|
for {
|
||
|
gameStatus()
|
||
|
checkLose()
|
||
|
checkWin()
|
||
|
|
||
|
checkEmpty:
|
||
|
for {
|
||
|
fmt.Printf("Guess: ")
|
||
|
//fmt.Scanln(&guess)
|
||
|
guess = scanLine()
|
||
|
|
||
|
if isEmpty(guess) == false && len([]rune(guess)) == 1 {
|
||
|
break checkEmpty
|
||
|
} else {
|
||
|
gameStatus()
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
if getLetter(guess) == true {
|
||
|
if alreadyCorrect(guess) == true {
|
||
|
fmt.Printf("[-] You've already guessed this correct letter")
|
||
|
time.Sleep(1 * time.Second)
|
||
|
} else {
|
||
|
correctChars = append(correctChars, guess)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if getLetter(guess) == false {
|
||
|
if alreadyWrong(guess) == true {
|
||
|
fmt.Printf("[-] You've already guessed this wrong letter")
|
||
|
time.Sleep(1 * time.Second)
|
||
|
} else {
|
||
|
fmt.Printf("Wrong!")
|
||
|
wrongChars = append(wrongChars, guess)
|
||
|
player.lives--
|
||
|
time.Sleep(1 * time.Second)
|
||
|
}
|
||
|
}
|
||
|
// Realized entering empty input would still cause "already guessed" errors
|
||
|
// because guess wasn't being reset
|
||
|
guess = ""
|
||
|
}
|
||
|
}
|