-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
84 lines (67 loc) · 1.46 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package main
import (
"fmt"
"strings"
)
var (
words string
wordCharSlice []string
wordState []string
blankWord []string
letter string
guesses int
inputChoice string
gameState bool
)
func newGame(gameState bool) {
if gameState == true {
fmt.Println("Random word choice in process..")
// words = []string{"batman", "holla", "giraffe", "superman"}
words = "batman"
wordCharSlice = strings.Split(words, "")
for i := 0; len(wordCharSlice) > i; i++ {
blankWord = append(blankWord, "_")
// buffer.WriteString("_ ")
}
fmt.Println(blankWord)
fmt.Println("Please choose a letter")
guesses = 1
fmt.Scanf("%s\n", &letter)
gameState = false
guess(blankWord, wordCharSlice, letter, guesses)
}
letter = ""
guess(blankWord, wordCharSlice, letter, guesses)
}
func guess(blankWord []string, wordCharSlice []string, letter string, guesses int) {
fmt.Println("b4 guess")
fmt.Println(guesses)
for guesses < 10 {
fmt.Println("a guess")
if letter == "" {
fmt.Println("Please choose a lettera")
fmt.Scanf("%s\n", &letter)
}
var i = 0
for _, l := range wordCharSlice {
if letter == l {
blankWord[i] = l
}
i++
}
fmt.Println(blankWord)
gameState = false
newGame(gameState)
}
}
func main() {
//to start game
fmt.Println("Type 'start' to begin.")
//input of user
fmt.Scanf("%s\n", &inputChoice)
//check if true
if inputChoice == "start" {
gameState := true
newGame(gameState)
}
}