func parseChunks(chunkData string) []*chunk.Chunk { result := []*chunk.Chunk{} for _, asciiMap := range chunk.SplitMaps(chunkData) { chunk, err := chunk.Parse(chunk.ParseSpec{"|.", '*'}, asciiMap) if err != nil { panic(err) } result = append(result, chunk) } return result }
func main() { for _, ch := range strings.Split(chunkFile, "\n\n") { c, err := chunk.Parse(chunk.ParseSpec{"|.", '*'}, ch) if err != nil { panic(err) } chunks = append(chunks, c) } chunks = chunk.GenerateVariants(chunks) gen := chunk.New(chunks[0], '#') gen.SetGrid(image.Pt(4, 4)) err := termbox.Init() if err != nil { panic(err) } defer termbox.Close() pegIdx := rand.Intn(len(gen.OpenPegs())) chunkIdx := 0 loop: for { draw(gen, pegIdx, chunkIdx) switch ev := termbox.PollEvent(); ev.Type { case termbox.EventKey: switch ev.Key { case termbox.KeyTab: pegIdx++ chunkIdx = 0 pegs := gen.OpenPegs() if pegIdx >= len(pegs) { pegIdx = 0 } case termbox.KeySpace: chunkIdx++ case termbox.KeyEnter: spawn(gen, chunks, pegIdx, chunkIdx) if len(gen.OpenPegs()) == 0 { pegIdx = 0 } else { pegIdx = rand.Intn(len(gen.OpenPegs())) } chunkIdx = rand.Intn(256) case termbox.KeyEsc: break loop } } } }