feat: add step counter.
Based on discussions on bubbletea github for when I got into issues with view. https://github.com/charmbracelet/bubbletea/discussions/1343#discussioncomment-12376381
This commit is contained in:
parent
118a8da1c2
commit
84e9e8fdea
4
main.go
4
main.go
@ -18,6 +18,7 @@ const (
|
|||||||
type gol struct {
|
type gol struct {
|
||||||
grid [ROW][COL]int
|
grid [ROW][COL]int
|
||||||
buffer [ROW][COL]int
|
buffer [ROW][COL]int
|
||||||
|
step int
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create array that holds field's to check for neighbours
|
// Create array that holds field's to check for neighbours
|
||||||
@ -75,6 +76,7 @@ func (g gol) Life() tea.Model {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
g.grid = g.buffer
|
g.grid = g.buffer
|
||||||
|
g.step++
|
||||||
return g
|
return g
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,7 +97,7 @@ func (g gol) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
|
|
||||||
// Let's draw this all simply
|
// Let's draw this all simply
|
||||||
func (g gol) View() string {
|
func (g gol) View() string {
|
||||||
var s string
|
s := fmt.Sprintf("Step: %d\n", g.step)
|
||||||
// Making sure to not draw the empty field around the array
|
// Making sure to not draw the empty field around the array
|
||||||
for i := 1; i < ROW-1; i++ {
|
for i := 1; i < ROW-1; i++ {
|
||||||
for j := 1; j < COL-1; j++ {
|
for j := 1; j < COL-1; j++ {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user