Improved maze rendering

main
Bryson Zimmerman 11 months ago
parent 6a06ba20d3
commit 9ee0a07c9c

@ -4,6 +4,7 @@ import technology.zim.data.Tile
import technology.zim.data.TileProperties import technology.zim.data.TileProperties
import technology.zim.data.WorldData import technology.zim.data.WorldData
import java.util.* import java.util.*
import technology.zim.data.Directions.*
//Singleton object containing a set of tiles //Singleton object containing a set of tiles
//Has helper functions included //Has helper functions included
@ -17,7 +18,7 @@ import java.util.*
// Which currently only contains the edges of the "graph", stored as directions // Which currently only contains the edges of the "graph", stored as directions
object World { object World {
//Default size should be 20 //Default size should be 10
val tiles = WorldData(ArrayList<ArrayList<TileProperties>>()) val tiles = WorldData(ArrayList<ArrayList<TileProperties>>())
var sizeX = 10 var sizeX = 10
var sizeY = 10 var sizeY = 10
@ -51,37 +52,58 @@ object World {
val str = StringBuilder() val str = StringBuilder()
//Reading left to right, top to bottom - can do a simple for each on the rows //Reading left to right, top to bottom - can do a simple for each on the rows
for(y in 0..tiles.value[0].size- 1) { for (y in 0..tiles.value[0].size - 1) {
//Upper line: Print each tile, print right-hand connections //Upper line: Print each tile, print right-hand connections
for (x in 0..tiles.value[0].size - 1) { for (x in 0..tiles.value[0].size - 1) {
str.append(fi) str.append(getTileShapeDoubles(World.get(Tile(x, y))))
if(tiles.value.get(x).get(y).isEast())
str.append(fi)
else
str.append(em)
}
//End upper line
str.appendLine()
//Lower line: Print downward connections
for (x in 0..tiles.value.size - 1) {
if(tiles.value.get(x).get(y).isSouth()) {
str.append(fi)
}
else
str.append(em)
str.append(em)
} }
//End lower line
str.appendLine() str.appendLine()
} }
str.appendLine() str.appendLine()
return str.toString() return str.toString()
} }
fun getTileShape(tile: TileProperties): Char {
return when(tile.connections) {
UP.dir+DOWN.dir+LEFT.dir+RIGHT.dir -> '╋'
UP.dir+DOWN.dir+LEFT.dir -> '┫'
UP.dir+DOWN.dir+RIGHT.dir -> '┣'
UP.dir+LEFT.dir+RIGHT.dir -> '┻'
DOWN.dir+LEFT.dir+RIGHT.dir -> '┳'
UP.dir+LEFT.dir -> '┛'
UP.dir + RIGHT.dir -> '┗'
DOWN.dir + LEFT.dir -> '┓'
DOWN.dir + RIGHT.dir -> '┏'
LEFT.dir+RIGHT.dir -> '━'
UP.dir+DOWN.dir -> '┃'
UP.dir -> '╹'
RIGHT.dir -> '╺'
DOWN.dir -> '╻'
LEFT.dir -> '╸'
else -> '•'
}
}
fun getTileShapeDoubles(tile: TileProperties): Char {
return when(tile.connections and(MANIFEST.inv()) and(INPATH.inv()) and(CHECKED.inv())) {
UP.dir+DOWN.dir+LEFT.dir+RIGHT.dir -> '╬'
UP.dir+DOWN.dir+LEFT.dir -> '╣'
UP.dir+DOWN.dir+RIGHT.dir -> '╠'
UP.dir+LEFT.dir+RIGHT.dir -> '╩'
DOWN.dir+LEFT.dir+RIGHT.dir -> '╦'
UP.dir+LEFT.dir -> '╝'
UP.dir + RIGHT.dir -> '╚'
DOWN.dir + LEFT.dir -> '╗'
DOWN.dir + RIGHT.dir -> '╔'
LEFT.dir+RIGHT.dir -> '═'
UP.dir+DOWN.dir -> '║'
UP.dir -> '╨'
RIGHT.dir -> '╞'
DOWN.dir -> '╥'
LEFT.dir -> '╡'
else -> '•'
}
}
//TODO: toString method
//Reads array left to right, top to bottom //Reads array left to right, top to bottom
//Only looks at SOUTH and EAST connections //Only looks at SOUTH and EAST connections
//Either connection exists or it does not, whitespace character for exists, some block-appearing char for not //Either connection exists or it does not, whitespace character for exists, some block-appearing char for not

@ -1,6 +1,7 @@
package technology.zim.data package technology.zim.data
//Data structure wrapper for a set of tiles //Data structure wrapper for a set of tiles
//Todo: Test converting to a single row-major array, multiplying the y value by row size to find the element position
@JvmInline @JvmInline
value class WorldData(val value: ArrayList<ArrayList<TileProperties>>) { value class WorldData(val value: ArrayList<ArrayList<TileProperties>>) {

Loading…
Cancel
Save