Adding interactive prompts
Planning to make a rudimentary hangman game, good practice for learning structs
This commit is contained in:
parent
fa015f4837
commit
ab76136b4b
|
@ -8,9 +8,23 @@ import (
|
|||
//"strconv"
|
||||
)
|
||||
|
||||
type PlayerStats struct {
|
||||
name string
|
||||
lives uint8
|
||||
}
|
||||
|
||||
var player PlayerStats
|
||||
var names = []string{}
|
||||
var err error
|
||||
var guess string
|
||||
var guessLetter rune
|
||||
|
||||
func scanLine() (line string) {
|
||||
in := bufio.NewReader(os.Stdin)
|
||||
line, err := in.ReadString('\n')
|
||||
catchErr(err)
|
||||
return line
|
||||
}
|
||||
|
||||
func main() {
|
||||
if len(os.Args) < 2 || len(os.Args) > 2 {
|
||||
|
@ -18,18 +32,28 @@ func main() {
|
|||
os.Exit(1)
|
||||
}
|
||||
|
||||
fmt.Printf("Welcome to the hanged man game!\nMay I know your name?\nName: ")
|
||||
// _, err = fmt.Scanln(&player.name)
|
||||
// catchErr(err)
|
||||
player.name = scanLine()
|
||||
|
||||
fmt.Println(player.name)
|
||||
|
||||
filePath := os.Args[1]
|
||||
randWord := getWord(filePath)
|
||||
|
||||
fmt.Printf("The chosen name is %v\n", randWord)
|
||||
fmt.Scan(&guess)
|
||||
// fmt.Scan(&guess)
|
||||
fmt.Scanln(&guessLetter)
|
||||
// if guess == randWord {
|
||||
// fmt.Printf("You win!\n")
|
||||
// } else {
|
||||
// fmt.Printf("You lose!\n")
|
||||
// }
|
||||
|
||||
if guess == randWord {
|
||||
fmt.Printf("You win!\n")
|
||||
} else {
|
||||
fmt.Printf("You lose!\n")
|
||||
}
|
||||
}
|
||||
|
||||
func letterCheck(char rune) {
|
||||
}
|
||||
|
||||
func catchErr(err error) {
|
||||
|
|
Loading…
Reference in New Issue