Package pr.battlebots.gen

Source Code of pr.battlebots.gen.WorldGen

package pr.battlebots.gen;

import java.util.Iterator;
import pr.battlebots.VecIterator;
import pr.battlebots.World;
import pr.battlebots.blocks.Block;
import pr.battlebots.blocks.BlockType;
import pr.lib.Vec;

public abstract class WorldGen implements IGen{

    protected World world;

    abstract BlockType getBlockFor(Vec p);

    abstract Vec getSouthWestCorner();

    abstract int getWidth();

    abstract int getHeight();

    void setWorld(World world) {
        this.world = world;
    }
   
    @Override
    public void gen(World world){
        this.setWorld(world);
        int startCol = this.getSouthWestCorner().x;
        int startRow = this.getSouthWestCorner().y;
        int lastRow = this.getWidth()+startRow;
        int lastCol = this.getHeight()+startCol;
        Iterator<Vec> iterator = new VecIterator(startRow, lastRow, startCol, lastCol);
       
        while(iterator.hasNext()) {
            Vec p = iterator.next();
            BlockType t = this.getBlockFor(p);

            if (t != null) {
                world.makeBlock(t, p);
            }
        }
    }
}
TOP

Related Classes of pr.battlebots.gen.WorldGen

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.