All pastes #2074004 Raw Edit

Miscellany

public java v1 · immutable
#2074004 ·published 2011-06-03 05:58 UTC
rendered paste body
import java.util.*;public class Mapper {	static Scanner ReadUserInput = new Scanner(System.in);	/**	 * @param args	 */	public static void main(String[] args) {		//I know...Looks stupid, but we're gonna make sure java works first  =P		//(Besides....Saying "Hello" is always more interesting than "Initializing Java..." Right?)		System.out.println("Hello Java!");		for (int i=0; i<10; i++){			System.out.println(i);		}						Map world_map = new Map();		world_map.set_height(2);		world_map.set_width(2);		world_map.createCells();				world_map.initialize_cells();						for (int i=0; i < world_map.get_height(); i++){			for (int j=0; j < world_map.get_width(); j++){				System.out.print(world_map.get_cell_data(i, j));			}				System.out.print("\n");				world_map.build_map();		}			}	}/************************End Of Class**************************************/import java.util.Random;public class Map {				private int height = 0;	private int width = 0;		 Cell[][] map_cells;	 Cell[] tmp_Cells;	 	 public void createCells(){		 System.out.println("Creating a New map with: " + height + " Rows and " + width + " Columns");		 map_cells = new Cell[height][width];		 for (int i=0; i < map_cells.length;i++){			 for (int j = 0; j < map_cells[i].length; j++){				 map_cells[i][j]=new Cell();			 }		 }		 System.out.println("Cells Initialized Sucessfully");	 }	public void set_height(int x){		height = x;		}	public void set_width(int x){		width = x;	}	public int get_height(){		return height;	}		public int get_width(){		return width;	}			public char get_cell_data(int x, int y){		return map_cells[x][y].getTerrain_Char();	}		public void initialize_cells(){		//initialize the map with random terrain. Clean it up in build_map()		Random generator = new Random();		for (int i = 0; i < map_cells.length; i++){			for (int j = 0; j< map_cells[i].length; j++){				map_cells[i][j].set_terrain(generator.nextInt(6));			}		}	}		public void print(String s){		System.out.println(s);	}		public void build_map(){		//Phase One: Scan through until the program finds a GrassLands		for (int i= 0; i < map_cells.length; i++){			for(int j= 0; j < map_cells[i].length; j++){				if ((map_cells[i][j].get_terrain()==3)&& !(map_cells[i][j].isVisited())){					map_cells[i][j].setVisited(true);										//Just enumerating the Cardinal directions as directions within the array					int N = i - 1;					int W = j - 1;					int S = i + 1;					int E = j + 1;																			if((i == 0)&(j == 0)){						System.out.println(i +" - " + j);						Cell[] tmp_Cell = {map_cells[i][E],map_cells[S][E],map_cells[S][j]};						tmp_Cells = tmp_Cell.clone();						print("i0j0");					}										else if((i == 0) & (j == map_cells[i].length)){						System.out.println(i +" - " + j);						Cell[] tmp_Cell = {map_cells[i][W],map_cells[S][W],map_cells[S][j]};						tmp_Cells = tmp_Cell.clone();						print("i0jw");					}					else if((i == map_cells.length)&&(j == 0)){						System.out.println(i +" - " + j);						Cell[] tmp_Cell = {map_cells[N][j],map_cells[N][E],map_cells[i][E]};						tmp_Cells = tmp_Cell.clone();						print("ihj0");					}					else if((i == map_cells.length)&&(j == map_cells[i].length)){						System.out.println(i +" - " + j);						Cell[] tmp_Cell = {map_cells[N][j],map_cells[N][W],map_cells[i][W]};						tmp_Cells = tmp_Cell.clone();						print("ihjw");					}					else if (i == 0){						System.out.println(i +" - " + j);						Cell[] tmp_Cell = {map_cells[i][W],map_cells[S][W],map_cells[S][j],map_cells[S][E],map_cells[i][E]};						tmp_Cells = new Cell[tmp_Cell.length];						tmp_Cells = tmp_Cell.clone();						print("i0");					}					else if(j == 0){						System.out.println(i +" - " + j);						Cell[] tmp_Cell = {map_cells[N][j],map_cells[N][E],map_cells[i][E],map_cells[S][E],map_cells[S][j]};						tmp_Cells = tmp_Cell.clone();						print("j0");					}					else if(j == map_cells[i].length){						System.out.println(i +" - " + j);						Cell[] tmp_Cell = {map_cells[N][j],map_cells[N][W],map_cells[i][W],map_cells[S][W],map_cells[S][j]};						tmp_Cells = tmp_Cell.clone();						print("jw");					}					else if(i == map_cells.length){						System.out.println(i +" - " + j);						Cell[] tmp_Cell = {map_cells[i][W],map_cells[N][W],map_cells[N][j],map_cells[N][E],map_cells[i][E]};						tmp_Cells = tmp_Cell.clone();						print("ih");					}					else{						System.out.println(i +" - " + j);						Cell[] tmp_Cell = {map_cells[i][W],map_cells[N][W],map_cells[N][j],map_cells[N][E],map_cells[i][E],map_cells[S][E],map_cells[S][j]};						tmp_Cells = tmp_Cell.clone();						print("else");					}					System.out.println(i +" - " + j);													/*This Comment Intentionally Left Blank*/									}		/*Just trying to tidy up the close Braces*/			}	/*You know...Make it look all Pretty*/		}/*Before you get to........*/	}}/************The Very End!*/			/**********************End Of Class********************/public class Cell {	/********************Getters and Setters**********************************************/		public int get_terrain(){		return terrain_type;	}		public void setTerrain_Name(String terrain_Name) {		Terrain_Name = terrain_Name;	}	public String getTerrain_Name() {		return Terrain_Name;	}	public void setTerrain_Char(char terrain_Char) {		Terrain_Char = terrain_Char;	}	public char getTerrain_Char() {		return Terrain_Char;	}	public void setPassable(boolean passable) {		this.passable = passable;	}	public boolean isPassable() {		return passable;	}	public void setShip_pass(boolean ship_pass) {		this.ship_pass = ship_pass;	}	public boolean isShip_pass() {		return ship_pass;	}	public void setBuildible(boolean buildible) {		this.buildible = buildible;	}	public boolean isBuildible() {		return buildible;	}	public void setVisited(boolean visited) {		this.visited = visited;	}	public boolean isVisited() {		return visited;	}	public void setCell_weight(float cell_weight) {		this.cell_weight = cell_weight;	}	public float getCell_weight() {		return cell_weight;	}/***********************************************************************************************************/		private boolean passable = false;		private boolean ship_pass = false;		private boolean buildible = false;		private boolean visited = false;				private int terrain_type;		private String Terrain_Name;		private char  Terrain_Char;							private float cell_weight=0;						private String[] aterrain_name = {"Ocean", "Shore", "River", "Grassland", "Forest","Mineable Stone","Non-Mineable Stone"};		private char[] aterrain_char= {'~','$','=','`','*','%','^'};		private boolean[] apassable = {false,true,false,true,true,false,false};		private boolean[] aship_pass ={true,false,false,false,false,false,false};		private boolean[] abuildible={false, false, false, true, true, false, false};						/**Should be a number between 0 and 6		 * @0 = Ocean = '~'		 * @1 = Shore = '$'		 * @2 = River = '='		 * @3 = Grassland = '`'		 * @4 = Forest = '*'		 * @5 = Minable stone = '%'		 * @6 = Non-Minable stone = '^'		 */				public void set_terrain(int x){			    terrain_type = x;				setTerrain_Name(aterrain_name[terrain_type]);				setTerrain_Char(aterrain_char[terrain_type]);				setPassable(apassable[terrain_type]);				setShip_pass(aship_pass[terrain_type]);				setBuildible(abuildible[terrain_type]);		}}			/******************************************End Of Class*****************************/