Adding interactive prompts

Planning to make a rudimentary hangman game, good practice for learning
structs
This commit is contained in:
raul 2024-02-09 21:28:57 +01:00
parent fa015f4837
commit ab76136b4b
1 changed files with 30 additions and 6 deletions

View File

@ -8,9 +8,23 @@ import (
//"strconv" //"strconv"
) )
type PlayerStats struct {
name string
lives uint8
}
var player PlayerStats
var names = []string{} var names = []string{}
var err error var err error
var guess string 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() { func main() {
if len(os.Args) < 2 || len(os.Args) > 2 { if len(os.Args) < 2 || len(os.Args) > 2 {
@ -18,18 +32,28 @@ func main() {
os.Exit(1) 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] filePath := os.Args[1]
randWord := getWord(filePath) randWord := getWord(filePath)
fmt.Printf("The chosen name is %v\n", randWord) 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) { func catchErr(err error) {