Det er intet stort, jeg er bare ved at lære Java struktur bedre at kende, med dens variabler og brug af ram.. jeg er bare ret nysgerrig i hvad jeg gør forkert, siden den klasse går helt amork i at initializere objekter.
Map
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package dk.minsk.games.map;
/**
*
* @author Martin Fryd Wochner
*/
public class Map {
private MapBlock[][][] _map;
private short _sizeX = 0;
private short _sizeY = 0;
private short _sizeZ = 0;
private int _loadedBlocks = 0;
public Map(short x, short y, short z) {
this._sizeX = x;
this._sizeY = y;
this._sizeZ = z;
this._map = new MapBlock[this._sizeZ][this._sizeY][this._sizeX];
}
public MapBlock getBlock(short x, short y, short z) throws MapException{
if(z < this._map.length){
if ( y < this._map[z].length){
if (x < this._map[z][y].length){
return this._map[z][y][x];
}
}
}
throw new MapException("Cordinate out of reach",x,y,z);
}
public short getSizeOfX(){
return this._sizeX;
}
public short getSizeOfY(){
return this._sizeY;
}
public short getSizeOfZ(){
return this._sizeZ;
}
public int getEstBlocks(){
return _sizeX*_sizeY*_sizeZ;
}
public int getLoadedBlocks(){
return this._loadedBlocks;
}
public void incLoadedBlocks(){
this._loadedBlocks++;
}
/**
* Generate the BlockMap
*/
public void Generate(){
MapGenerator mg = new MapGenerator(this);
}
}
MapBlock
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package dk.minsk.games.map;
import java.util.Random;
/**
*
* @author Martin Fryd Wochner
*/
public class MapBlock {
private short _x = 0;
private short _y = 0;
private short _z = 0;
private Map _map;
private byte biome = 0;
public MapBlock(short x, short y, short z, Map map) {
_x = x;
_y = y;
_z = z;
_map = map;
}
public void Generate(){
Random r = new Random();
biome = (byte)r.nextInt(127);
}
public MapBlock getAdjNorth() throws MapException{
return _map.getBlock(_x, (short)(_y -1), _z);
}
public MapBlock getAdjSouth() throws MapException{
return _map.getBlock(_x, (short)(_y+1), _z);
}
public MapBlock getAdjWest() throws MapException{
return _map.getBlock((short)(_x-1), _y, _z);
}
public MapBlock getAdjEast() throws MapException{
return _map.getBlock((short)(_x+1), _y, _z);
}
public MapBlock getAdjDown() throws MapException{
return _map.getBlock(_x, _y, (short)(_z+1));
}
public MapBlock getAdjUp() throws MapException{
return _map.getBlock(_x, _y, (short)(_z-1));
}
}