Skip to content

Commit e8be803

Browse files
committed
feat(snake): Add color to game pieces
1 parent 7e5c70b commit e8be803

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

internal/app/snake/snake.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"time"
77

88
tea "github.com/charmbracelet/bubbletea"
9+
"github.com/charmbracelet/lipgloss"
910
)
1011

1112
type moveMsg struct{}
@@ -35,6 +36,7 @@ var (
3536
type player struct {
3637
body []vector
3738
dir vector
39+
style lipgloss.Style
3840
}
3941

4042
func (p *player) move(m model, foodPos vector) {
@@ -60,6 +62,7 @@ func (p player) headChar() rune {
6062

6163
type model struct {
6264
foodPos vector
65+
foodStyle lipgloss.Style
6366
player player
6467
}
6568

@@ -133,16 +136,16 @@ func (m model) View() string {
133136
for i, b := range m.player.body {
134137
if b.x == x && b.y == y {
135138
if i == 0 {
136-
s += string(m.player.headChar())
139+
s += m.player.style.Render(string(m.player.headChar()))
137140
} else {
138-
s += "*"
141+
s += m.player.style.Render("*")
139142
}
140143
drew = true
141144
}
142145
}
143146
if !drew {
144147
if x == m.foodPos.x && y == m.foodPos.y {
145-
s += "0"
148+
s += m.foodStyle.Render("0")
146149
drew = true
147150
}
148151
}
@@ -164,9 +167,11 @@ func initialModel() tea.Model {
164167
x: rand.IntN(20),
165168
y: rand.IntN(20),
166169
},
170+
foodStyle: lipgloss.NewStyle().Foreground(lipgloss.Color("#ff0000")),
167171
player: player{
168172
body: []vector{{6, 6}},
169173
dir: dirRight,
174+
style: lipgloss.NewStyle().Foreground(lipgloss.Color("32")),
170175
},
171176
}
172177
}

0 commit comments

Comments
 (0)