Cleaned up code for checking already guessed chars
This commit is contained in:
parent
d8983f8591
commit
894cd5c7c2
66
main.go
66
main.go
|
@ -121,6 +121,40 @@ func checkLose() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// func alreadyGuessed() (isGuess bool) {
|
||||||
|
// var isAlreadyGuessed bool = false
|
||||||
|
// for _, v := range wrongChars {
|
||||||
|
// if v == guess {
|
||||||
|
// isAlreadyGuessed = true
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// for _, v := range revealedChars {
|
||||||
|
// if v == guess {
|
||||||
|
// isAlreadyGuessed = true
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// return isAlreadyGuessed
|
||||||
|
// }
|
||||||
|
func alreadyWrong() (isGuess bool) {
|
||||||
|
var isAlreadyGuessed bool = false
|
||||||
|
for _, v := range wrongChars {
|
||||||
|
if v == guess {
|
||||||
|
isAlreadyGuessed = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return isAlreadyGuessed
|
||||||
|
}
|
||||||
|
|
||||||
|
func alreadyCorrect() (isGuess bool) {
|
||||||
|
var isAlreadyGuessed bool = false
|
||||||
|
for _, v := range revealedChars {
|
||||||
|
if v == guess {
|
||||||
|
isAlreadyGuessed = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return isAlreadyGuessed
|
||||||
|
}
|
||||||
|
|
||||||
func game() {
|
func game() {
|
||||||
for {
|
for {
|
||||||
gameStatus()
|
gameStatus()
|
||||||
|
@ -132,13 +166,7 @@ func game() {
|
||||||
|
|
||||||
// TODO: Add checking for both wrong and correct characters
|
// TODO: Add checking for both wrong and correct characters
|
||||||
if getLetter(guess) != true {
|
if getLetter(guess) != true {
|
||||||
var isAlreadyWrong bool = false
|
if alreadyWrong() == true {
|
||||||
for _, v := range wrongChars {
|
|
||||||
if v == guess {
|
|
||||||
isAlreadyWrong = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if isAlreadyWrong == true {
|
|
||||||
fmt.Printf("You've already guessed this letter")
|
fmt.Printf("You've already guessed this letter")
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
} else {
|
} else {
|
||||||
|
@ -148,6 +176,30 @@ func game() {
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if getLetter(guess) == true {
|
||||||
|
// if alreadyGuessed() == true {
|
||||||
|
// fmt.Printf("You've already guessed this letter")
|
||||||
|
// time.Sleep(1 * time.Second)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// var isAlreadyWrong bool = false
|
||||||
|
// for _, v := range wrongChars {
|
||||||
|
// if v == guess {
|
||||||
|
// isAlreadyWrong = true
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// if isAlreadyWrong == true {
|
||||||
|
// fmt.Printf("You've already guessed this letter")
|
||||||
|
// time.Sleep(1 * time.Second)
|
||||||
|
// } else {
|
||||||
|
// fmt.Printf("Wrong!")
|
||||||
|
// wrongChars = append(wrongChars, guess)
|
||||||
|
// player.lives--
|
||||||
|
// time.Sleep(1 * time.Second)
|
||||||
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue