Skip to content

Commit 900931f

Browse files
authored
Merge pull request #3 from mdb/mdb/correct-var-refs
use struct field rather than global var
2 parents c3a4f64 + ef09779 commit 900931f

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION = 0.0.3
1+
VERSION = 0.0.4
22
SOURCE = ./...
33

44
.DEFAULT_GOAL := build

main.go

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,10 @@ var (
3232
)
3333

3434
type wordle struct {
35-
wordLength int
36-
maxGuesses int
37-
word string
38-
guesses []map[string][wordLength]tileColor
39-
in io.Reader
40-
out io.Writer
35+
word string
36+
guesses []map[string][wordLength]tileColor
37+
in io.Reader
38+
out io.Writer
4139
}
4240

4341
func (w *wordle) displayRow(word string, colors [wordLength]tileColor) {
@@ -96,13 +94,13 @@ func (w *wordle) getLetterTileColors(guess string) [wordLength]tileColor {
9694

9795
func (w *wordle) displayEmptyRows(guessCount int) {
9896
emptyGuessChars := []string{}
99-
for i := 0; i < w.wordLength; i++ {
97+
for i := 0; i < wordLength; i++ {
10098
emptyGuessChars = append(emptyGuessChars, "*")
10199
}
102100

103101
emptyGuess := strings.Join(emptyGuessChars, "")
104102
emptyTileColors := w.getLetterTileColors(emptyGuess)
105-
emptyRowCount := w.maxGuesses - guessCount - 1
103+
emptyRowCount := maxGuesses - guessCount - 1
106104

107105
for i := 0; i < emptyRowCount; i++ {
108106
w.displayRow(emptyGuess, emptyTileColors)
@@ -119,9 +117,9 @@ func (w *wordle) run() {
119117
w.write(fmt.Sprintf("Version: \t%s\n", version))
120118
w.write("Info: \t\thttps://github.com/mdb/wordle\n")
121119
w.write("About: \t\tA CLI adaptation of Josh Wardle's Wordle (https://powerlanguage.co.uk/wordle/)\n\n")
122-
w.write(fmt.Sprintf("Guess a %v-letter word within %v guesses...\n", w.wordLength, w.maxGuesses))
120+
w.write(fmt.Sprintf("Guess a %v-letter word within %v guesses...\n", wordLength, maxGuesses))
123121

124-
for guessCount := 0; guessCount < w.maxGuesses; guessCount++ {
122+
for guessCount := 0; guessCount < maxGuesses; guessCount++ {
125123
w.write(fmt.Sprintf("\nGuess (%v/%v): ", len(w.guesses)+1, maxGuesses))
126124

127125
reader.Scan()
@@ -154,11 +152,9 @@ func (w *wordle) run() {
154152

155153
func newWordle(word string, in io.Reader, out io.Writer) *wordle {
156154
return &wordle{
157-
wordLength: wordLength,
158-
maxGuesses: maxGuesses,
159-
word: word,
160-
in: in,
161-
out: out,
155+
word: word,
156+
in: in,
157+
out: out,
162158
}
163159
}
164160

0 commit comments

Comments
 (0)