public Map(string path) { parser = new Parser(path); ArrayList current; landfills = new ArrayList(); selected = new Point(-1,-1); current = parser.getSection("ATTRIBUTES"); foreach (string[] line in current) { if(line[0].Equals("tileset")) { tilesetName = line[1]; tiles = new tileset(tilesetName); } else if(line[0].Equals("size")) { width = int.Parse(line[1]); height = int.Parse(line[2]); } else if(line[0].Equals("description")) { description = ""; for(int i=1;i<line.Length;i++) description += line[i]; } } m = new tile_t[width,height]; current = parser.getSection("CONTENT"); for(int x=0;x<width;x++) { for(int y=0;y<height;y++) { m[x,y] = new tile_t(((string[])current[y])[x]); } } current = parser.getSection("RESOURCES"); foreach(string[] line in current) { if(line[0].Equals("landfill")) addLandfill(int.Parse(line[2])-1,int.Parse(line[3])-1,int.Parse(line[1]),int.Parse(line[4]),int.Parse(line[5])); else if(line[0].Equals("oil")) addOilWell(int.Parse(line[1])-1,int.Parse(line[2])-1,0,int.Parse(line[3]),int.Parse(line[4])); } current = parser.getSection("PLAYERS"); foreach(string[] line in current) { if(line.Length > 1) numPlayers++; } }
public Map(string tilePath, int numX, int numY) { landfills = new ArrayList(); selected = new Point(-1,-1); tilesetName = tilePath; width = numX; height = numY; tiles = new tileset(tilesetName); parser = new Parser(); m = new tile_t[width,height]; tile defaultTile = (tile)tiles.getAbsTiles()[0]; for(int y=0;y<height;y++) for(int x=0;x<width;x++) m[x,y] = new tile_t(defaultTile); }
public tile_t(tile_t old) { landf = old.landf; tile_p = old.myTile; }
bool equals(tile_t[,] t1, tile_t[,] t2) { try { for(int x=0;x<width;x++) for(int y=0;y<height;y++) if(!t1[x,y].myTile.Equals(t2[x,y].myTile)) return false; } catch(Exception) { return false; } return true; }
tile_t[,] currentState() { tile_t[,] newM = new tile_t[width,height]; for(int x = 0;x<width;x++) for(int y = 0;y<height;y++) newM[x,y] = new tile_t(m[x,y]); return newM; }
public void resize(int sizeX, int sizeY) { tile_t[,] newmap = new tile_t[sizeX, sizeY]; int minSizeX = Math.Min(sizeX, width), minSizeY = Math.Min(sizeY, height); for(int yi=0; yi<height; yi++) for(int xi=0; xi<width; xi++) { if(yi<minSizeY && xi<minSizeX) newmap[xi,yi] = m[xi,yi]; else newmap[xi,yi] = new tile_t((tile)tiles.getAbsTiles()[0]); } width = sizeX; height = sizeY; m = newmap; }
public void makeVertSymmetric() { int oldHeight = height; resize(width, height*2); for(int yi=0; yi<oldHeight; yi++) for(int xi=0; xi<width; xi++) { m[xi, height-1-yi] = new tile_t(tiles.mirrorVert(m[xi, yi].myTile)); } ArrayList land = (ArrayList)landfills.Clone(); foreach(landfill l in land) { if(l.GetType()==typeof(oilwell)) addOilWell(l.center.X-1,height-1-l.center.Y,0); else addLandfill(l.center.X-1,height-1-l.center.Y,0); } }
public void makeHorizSymmetric() { int oldWidth = width; resize(width*2, height); for(int yi=0; yi<height; yi++) for(int xi=0; xi<oldWidth; xi++) { m[width-1-xi, yi] = new tile_t(tiles.mirrorHoriz(m[xi, yi].myTile)); } ArrayList land = (ArrayList)landfills.Clone(); foreach(landfill l in land) { if(l.GetType()==typeof(oilwell)) addOilWell(width-1-l.center.X,l.center.Y-1,0); else addLandfill(width-1-l.center.X,l.center.Y-1,0); } }