Corrected some bugs for when it came to parsing

and writing mazes
This commit is contained in:
Karma Riuk
2023-08-10 19:13:24 +02:00
parent 3ef61967a5
commit 42cc4f8717
3 changed files with 28 additions and 6 deletions

View File

@ -56,17 +56,28 @@ func (w *ImageWriter) Write() error {
width, height = w.CellWidth, w.CellHeight
for i, from := range w.Maze.Solution[:len(w.Maze.Solution)-1] {
to := w.Maze.Solution[i+1]
if from.Coords.X == to.Coords.X {
// Fill verticallly
x0 = from.Coords.X * w.CellWidth
for y := from.Coords.Y; y < to.Coords.Y; y++ {
y0 = y * w.CellHeight
w.draw(x0, y0, width, height, colors[c])
c++
if from.Coords.Y < to.Coords.Y {
for y := from.Coords.Y; y < to.Coords.Y; y++ {
y0 = y * w.CellHeight
w.draw(x0, y0, width, height, colors[c])
c++
}
} else {
for y := from.Coords.Y; y > to.Coords.Y; y-- {
y0 = y * w.CellHeight
w.draw(x0, y0, width, height, colors[c])
c++
}
}
y0 = to.Coords.Y * w.CellHeight
w.draw(x0, y0, width, height, colors[c])
} else {
// Fill horizontally
y0 = from.Coords.Y * w.CellHeight
if from.Coords.X < to.Coords.X {

View File

@ -58,6 +58,9 @@ func (w *StringsWriter) fillHorizontally(from maze.Coordinates, to maze.Coordina
func (w *StringsWriter) fillVertically(from maze.Coordinates, to maze.Coordinates, char byte) {
x := from.X
if from.Y > to.Y {
from, to = to, from
}
for y := from.Y; y <= to.Y; y++ {
w.lines[y][x] = char
}