Level Reader

One megabyte is 1048576 bytes. Also a BufferedOutputStream won’t make anything faster unless you’re over a network. All flushing is done when you close() then PrintWriter, rendering the BOS useless :wink:

I’ve created this for the writer. It doesn’t work though… And yes, I know, it’s not pretty in the least bit.

package waffles.main;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;

public class DataWriter {
	public static String[][] writeData;
	public static  ArrayList<Platform> Platforms = new ArrayList<Platform>();
	public static ArrayList<Entity> Robots = new ArrayList<Entity>();
	public static ArrayList<ItemWaffle> WaffleCoins = new ArrayList<ItemWaffle>();
	public static ArrayList<Bullet> Bullets = new ArrayList<Bullet>();
	public static ArrayList<Wall> Walls = new ArrayList<Wall>();
	public static ArrayList<Wall> BackgroundWalls = new ArrayList<Wall>();
	public static ArrayList<Door> Elevators = new ArrayList<Door>();
	public static ArrayList<ArrayList<String>> newData = new ArrayList<ArrayList<String>>();
	@SuppressWarnings("unchecked")
	public static void DataWriter(ArrayList<ArrayList<?>> LevelData){
		//setup
		Platforms = (ArrayList<Platform>) LevelData.get(0);
		Robots = (ArrayList<Entity>) LevelData.get(1);
		WaffleCoins = (ArrayList<ItemWaffle>) LevelData.get(2);
		Bullets = (ArrayList<Bullet>) LevelData.get(3);
		Walls = (ArrayList<Wall>) LevelData.get(4);
		BackgroundWalls = (ArrayList<Wall>) LevelData.get(5);
		Elevators = (ArrayList<Door>) LevelData.get(6);
	}
	public static void CloneFromLevel(){
		Platforms = Level.Platforms;
		Robots = Level.Robots;
		WaffleCoins = Level.WaffleCoins;
		Bullets = Level.Bullets;
		Walls = Level.Walls;
		BackgroundWalls = Level.BackgroundWalls;
		Elevators = Level.Elevators;
		
	}
	
	public static void WriteToFile(String filename){
		try{
			BufferedWriter writer = new BufferedWriter(new FileWriter(filename + ".lvl"));
			for (int y = 0;y < newData.size();y++){
				for (int x = 0;x < newData.get(y).size();x++){
					String inf = null;
					inf = newData.get(y).get(x);
					if (inf == null)
						inf = "0:";
					writer.write(inf);
				}
				writer.newLine();
			}
		} catch(IOException e){
			throw new RuntimeException("Error in creating level file!");
		}
	}
	public static void SaveMatrix(){
	//	try{
			CreateMatrixBase();
                        //Please ignore the obvious error that i made where i forgot to change all of the gets to their respective lists..

			for (int x = 0;x < Platforms.size();x++){
				newData.get((int) Platforms.get(x).y).add((int) Platforms.get(x).x, "1:");
			}
			for (int x = 0;x < Robots.size();x++){
				newData.get((int) Platforms.get(x).y).add((int) Platforms.get(x).x, "2:");
			}
			for (int x = 0;x < WaffleCoins.size();x++){
				newData.get((int) Platforms.get(x).y).add((int) Platforms.get(x).x, "3:");
			}
			for (int x = 0;x < Bullets.size();x++){
				newData.get((int) Platforms.get(x).y).add((int) Platforms.get(x).x, "3:");
			}
			for (int x = 0;x < Walls.size();x++){
				newData.get((int) Platforms.get(x).y).add((int) Platforms.get(x).x, "4:");
			}
			for (int x = 0;x < BackgroundWalls.size();x++){
				newData.get((int) Platforms.get(x).y).add((int) Platforms.get(x).x, "5:");
			}
			for (int x = 0;x < Elevators.size();x++){
				newData.get((int) Platforms.get(x).y).add((int) Platforms.get(x).x, "6:");
			}
//		}catch(Exception e){
	//		
	//		throw new RuntimeException("Level is too big!");	
	//	}

	}
	public static void CreateMatrixBase(){
		for (int y = 0; y < 50000;y++){
			for (int x = 0;x < 50000; x++){
				newData.get(y).add(x,"0:");
			}
		}
	}
}