Compare commits

...

2 Commits

Author SHA1 Message Date
Jake 147cb22e88 fix: score -1 if out of guesses
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/tag Build is passing Details
2022-01-26 10:28:27 +00:00
Jake 3ab9f195a3 fix: don't show word on replay 2022-01-26 10:27:55 +00:00
3 changed files with 16 additions and 6 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,

10
main.go
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
@ -145,8 +145,10 @@ func (m model) View() string {
s += promptStyle.Render(footer) + "\n"
} else {
msg := ""
if m.board.CurrentGuess >= 6 {
msg += fmt.Sprintf("Oof! The word was %s.", m.board.Solution)
if m.board.CurrentGuess == -1 {
if m.board.Solution != "" {
msg += fmt.Sprintf("Oof! The word was %s.", m.board.Solution)
}
} else {
msg += fmt.Sprintf("Congrats! You guessed in %d.", m.board.CurrentGuess)
}