mirror of
https://gitlab1.ptb.de/waltem01/Matrix
synced 2024-12-26 12:01:45 +00:00
better setup structure
This commit is contained in:
parent
e57b501178
commit
b66f12b7c6
12
conway.go
12
conway.go
@ -59,17 +59,16 @@ func initGrid(width, height int, parent ...[][]Cell) ([][]Cell, error) {
|
|||||||
return cells, nil
|
return cells, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
const FPS = 10
|
|
||||||
|
|
||||||
var grid [][]Cell
|
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)
|
grid, _ = initGrid(width, height)
|
||||||
|
|
||||||
// Prepare
|
// Prepare ticker and finishing flag
|
||||||
ticker := time.NewTicker(time.Second / FPS)
|
ticker := time.NewTicker(time.Second / time.Duration(FPS))
|
||||||
done := make(chan bool)
|
done := make(chan bool)
|
||||||
|
|
||||||
|
// Run game loop
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
select {
|
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)) {
|
func draw(callback func([][]Cell)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user