fix: score -1 if out of guesses
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/tag Build is passing Details

This commit is contained in:
Jake 2022-01-26 10:28:13 +00:00
parent 3ab9f195a3
commit 147cb22e88
3 changed files with 12 additions and 4 deletions

View File

@ -46,8 +46,11 @@ func (b *Board) AddWord(word string) string {
}
b.CurrentGuess += 1
if len(correct) == 5 || b.CurrentGuess >= 6 {
if len(correct) == 5 {
b.Done = true
} else if b.CurrentGuess >= 6 {
b.Done = true
b.CurrentGuess = -1
}
return ""

View File

@ -35,7 +35,12 @@ func ToGame(b *game.Board) *Game {
Lines: []Line{},
}
for i := 0; i < b.CurrentGuess; i++ {
to := b.CurrentGuess
if b.CurrentGuess == -1 {
to = 6
}
for i := 0; i < to; i++ {
g.Lines = append(g.Lines, Line{
Word: string(b.Guesses[i].Letters),
Correct: b.Guesses[i].Correct,

View File

@ -84,7 +84,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
// clear input
m.buffer = []rune{}
// save if win
// save if done
if m.board.Done {
err := score.SaveBoard(m.board)
if err != nil {
@ -114,7 +114,7 @@ func (m model) View() string {
for i, guess := range m.board.Guesses {
line := " "
for j := 0; j < 5; j++ {
if i < m.board.CurrentGuess {
if i < m.board.CurrentGuess || m.board.CurrentGuess == -1 {
style := charEmptyStyle
if util.ContainsInt(guess.Correct, j) {
style = charCorrectStyle