@ -1,6 +1,7 @@
package technology.zim
package technology.zim
import technology.zim.data.Directions
import technology.zim.data.Directions
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.*
@ -13,38 +14,35 @@ import java.util.*
//Each element contains a TileProperties
//Each element contains a TileProperties
// Which currently only contains the edges of the "graph", stored as directions
// Which currently only contains the edges of the "graph", stored as directions
class World ( private val tiles : WorldData ) {
object World {
val tiles = WorldData ( ArrayList < ArrayList < TileProperties > > ( ) )
//TODO: Constructor that calls Mazefinder algorithm with given dimensions,
constructor ( xmin : Int , ymin : Int ) : this ( WorldData ( xmin , ymin ) )
//Returns a coordinate pair
//Returns a coordinate pair
fun getRandomLocation ( ) : Pair< Int , Int > {
fun getRandomLocation ( ) : Tile {
return Pair( ( 0. . tiles . data . size ) . random ( ) , ( 0. . tiles . data [ 0 ] . size ) . random ( ) )
return Tile( Pair( ( 0. . tiles . data . size ) . random ( ) , ( 0. . tiles . data [ 0 ] . size ) . random ( ) ) )
}
}
//Get the properties of the tile at the given coordinates
//Get the properties of the tile at the given coordinates
fun tile( coords : Pair < Int , Int > ) : TileProperties {
fun getProperties( tile : Tile ) : TileProperties {
return tiles . data . elementAt ( coords. first ) . elementAt ( coords . second )
return tiles . data . elementAt ( tile. loc . first ) . elementAt ( tile . loc . second )
}
}
//TODO: Add function for creating connections
//fun addConnection(at: Pair<Int, Int>, dir: Directions)
//fun addConnection(at: Pair<Int, Int>, dir: Directions)
//Sort out what cells are connected. Induces some CPU overhead compared to storing a simple list
//Sort out what cells are connected. Induces some CPU overhead compared to storing a simple list
//Benefit is smaller memory footprint by using references to singleton enums
//Benefit is smaller memory footprint by using references to singleton enums
fun getConnections ( at : Pair< Int , Int > ) : Set < Pair < Int , Int > > {
fun getConnections ( at : Tile) : Set < Tile > {
val listTiles = ArrayList < Pair< Int , Int > > ( )
val listTiles = ArrayList < Tile > ( )
for ( dir : Directions in til e( at ) . connections ) {
for ( dir : Directions in getProper ties ( at ) . connections ) {
//Use the ghost of linear algebra to identify potential neighbor tiles
//Use the ghost of linear algebra to identify potential neighbor tiles
val candidateTile = Pair< Int , Int > ( at . first + dir . dif . first , at . second + dir . dif . second )
val candidateTile = Tile( Pair ( at . loc . first + dir . dif . first , at . loc. second + dir . dif . second ) )
//Ensure that the tile is within bounds
//Ensure that the tile is within bounds
if ( candidateTile . first > 0 &&
if ( candidateTile . loc. first > 0 &&
candidateTile . second > 0 &&
candidateTile . loc. second > 0 &&
candidateTile . first < tiles . data . size &&
candidateTile . loc. first < tiles . data . size &&
candidateTile . second < tiles . data [ candidateTile . first ] . size ) {
candidateTile . loc. second < tiles . data [ candidateTile . loc . first ] . size ) {
listTiles . add ( candidateTile )
listTiles . add ( candidateTile )
}
}
}
}