diff --git a/conway.go b/conway.go index 2c5c05a..816db99 100644 --- a/conway.go +++ b/conway.go @@ -59,17 +59,16 @@ func initGrid(width, height int, parent ...[][]Cell) ([][]Cell, error) { return cells, nil } -const FPS = 10 - var grid [][]Cell -func setup(callback func([][]Cell), width, height int) { +func setup(callback func([][]Cell), width, height, FPS int) chan bool { grid, _ = initGrid(width, height) - // Prepare - ticker := time.NewTicker(time.Second / FPS) + // Prepare ticker and finishing flag + ticker := time.NewTicker(time.Second / time.Duration(FPS)) done := make(chan bool) + // Run game loop go func() { for { select { @@ -80,6 +79,9 @@ func setup(callback func([][]Cell), width, height int) { } } }() + + // Return flag to be stopped outside + return done } func draw(callback func([][]Cell)) {