Cleaning up code and adding hiddenChar viewer

This commit is contained in:
raul 2024-02-12 07:00:25 +01:00
parent 092619f4bb
commit 8ab370f705
2 changed files with 11 additions and 3 deletions

View File

@ -1,3 +1,3 @@
module file-reader module file-reader
go 1.21.6 go 1.22

View File

@ -26,6 +26,9 @@ var names = []string{}
var err error var err error
var guess string var guess string
var guessLetter rune var guessLetter rune
var filePath string = os.Args[1]
var randWord string = getWord(filePath)
var hiddenChars []string
func scanLine() (line string) { func scanLine() (line string) {
in := bufio.NewReader(os.Stdin) in := bufio.NewReader(os.Stdin)
@ -41,6 +44,10 @@ func main() {
os.Exit(1) os.Exit(1)
} }
for range randWord {
hiddenChars = append(hiddenChars, "_")
}
for { for {
clear() clear()
@ -79,12 +86,13 @@ func gameStatus() {
clear() clear()
fmt.Println("Player:", player.name) fmt.Println("Player:", player.name)
fmt.Println("Lives:", player.lives) fmt.Println("Lives:", player.lives)
fmt.Println("Word:", hiddenChars)
} }
func game() { func game() {
clear() clear()
filePath := os.Args[1] //filePath := os.Args[1]
randWord := getWord(filePath) //randWord := getWord(filePath)
for { for {
gameStatus() gameStatus()
if player.lives < 0 { if player.lives < 0 {