sdl2-life

Conway's Game of Life with go-sdl2
git clone https://www.brianlane.com/git/sdl2-life
Log | Files | Refs | README

commit e53b6ca9c41e190991ddc75bb8cb7bd10a788158
parent 38794017c71a664440f4a09554c199f0187e7b71
Author: Brian C. Lane <bcl@brianlane.com>
Date:   Thu, 24 Nov 2022 11:30:19 -0800

Add -empty flag to start with an empty world

Diffstat:
Mmain.go | 10++++++----
1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/main.go b/main.go @@ -35,6 +35,7 @@ type cmdlineArgs struct { Fps int // Frames per Second PatternFile string // File with initial pattern Pause bool // Start the game paused + Empty bool // Start with empty world } /* commandline defaults */ @@ -51,6 +52,7 @@ var cfg = cmdlineArgs{ Fps: 10, PatternFile: "", Pause: false, + Empty: false, } /* parseArgs handles parsing the cmdline args and setting values in the global cfg struct */ @@ -67,6 +69,7 @@ func parseArgs() { flag.IntVar(&cfg.Fps, "fps", cfg.Fps, "Frames per Second update rate (10fps)") flag.StringVar(&cfg.PatternFile, "pattern", cfg.PatternFile, "File with initial pattern to load") flag.BoolVar(&cfg.Pause, "pause", cfg.Pause, "Start the game paused") + flag.BoolVar(&cfg.Empty, "empty", cfg.Empty, "Start with empty world") flag.Parse() } @@ -134,10 +137,7 @@ func (g *LifeGame) InitializeCells() { } } - if len(cfg.PatternFile) == 0 { - g.InitializeRandomCells() - } else { - + if len(cfg.PatternFile) > 0 { // Read all of the pattern file for parsing f, err := os.Open(cfg.PatternFile) if err != nil { @@ -165,6 +165,8 @@ func (g *LifeGame) InitializeCells() { if err != nil { log.Fatalf("Error reading pattern file: %s", err) } + } else if !cfg.Empty { + g.InitializeRandomCells() } var err error