Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 42 additions & 26 deletions termle.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,36 +54,52 @@ func main() {
rand.Seed(time.Now().UnixNano())

var day int
if *randomFlag {
day = randomDay()
} else {
day = *dayFlag
}
playing := true
day = *dayFlag

for playing {
if *randomFlag {
day = randomDay()
}

g := newGame(day)
s := bufio.NewScanner(os.Stdin)
g := newGame(day)
s := bufio.NewScanner(os.Stdin)

g.printTurn()
for !g.complete && s.Scan() {
guess := strings.ToUpper(strings.TrimSpace(s.Text()))
if !valid.MatchString(guess) {
g.printTurnWithError("Please enter a 5 letter word")
continue
g.printTurn()
for !g.complete && s.Scan() {
guess := strings.ToUpper(strings.TrimSpace(s.Text()))
if !valid.MatchString(guess) {
g.printTurnWithError("Please enter a 5 letter word")
continue
}
if _, ok := g.validGuesses[guess]; !ok {
g.printTurnWithError("Not in word list")
continue
}
g.addGuess(guess)
g.printTurn()
}
if _, ok := g.validGuesses[guess]; !ok {
g.printTurnWithError("Not in word list")
continue
if s.Err() != nil {
panic(s.Err())
}
// prevents answer from printing if user used a signal to end the program
// scanner.Err() returns nil if io.EOF
if g.complete {
g.printShareableScore()
}

if *randomFlag {
fmt.Println()
fmt.Print("Continue Playing?(y/n/(default: n)>")
s.Scan()
if strings.TrimSpace(s.Text()) == "y" {
continue
} else {
playing = false
}
} else {
playing = false
}
g.addGuess(guess)
g.printTurn()
}
if s.Err() != nil {
panic(s.Err())
}
// prevents answer from printing if user used a signal to end the program
// scanner.Err() returns nil if io.EOF
if g.complete {
g.printShareableScore()
}
}

Expand Down