public TileList(XDocument doc) { foreach (var elem in doc.Root.Descendants()) { if (elem.Name == "Room") { Add(Room.Parse(elem).AsLevelPart()); } else if (elem.Name == "Walls") { Add(BorderWalls.Parse(elem).AsLevelPart()); } else if (elem.Name == "Wall") { Add(Wall.Parse(elem).AsLevelPart()); } else if (elem.Name == "Floor") { Add(Floor.Parse(elem).AsLevelPart()); } else if (elem.Name == "Tile") { Add(Tile.Parse(elem)); } } }
public Wall(BorderWalls b) { StartCell = b.StartCell; EndCell = b.EndCell; Type = b.Type; Theme = b.Theme; Traversable = false; }
/// <summary> /// Removes the Walls to ListObjects and adds all relevant cells to the grid /// </summary> /// <param name="r">Walls to add</param> /// <param name="Tiles">List of tiles generated by the borderawlls</param> /// <returns>Success</returns> private bool Remove(BorderWalls w) { try { LevelParts.Remove(w); return(true); } catch { return(false); } }
/// <summary> /// Adds the Walls to ListObjects and adds all relevant cells to the grid /// </summary> /// <param name="r">Walls to add</param> /// <param name="Tiles">List of tiles generated by the borderawlls</param> /// <returns>Success</returns> private bool Add(BorderWalls w) { try { LevelParts.Add(w); return(true); } catch { return(false); } }
/// <summary> /// Removes the Walls to ListObjects and adds all relevant cells to the grid /// </summary> /// <param name="w">Walls to add</param> /// <param name="Tiles">Listof tiles generated by the borderawlls</param> /// <param name="dontRemove">True means the item added will not be added to the list of Levelobjects</param> /// <returns>Success</returns> private void Remove(BorderWalls w, out List <Tile> Tiles, bool dontRemove = false) { //we're going to be getting them a lot otherwise Index2D start = new Index2D(Math.Min(w.StartCell.X, w.EndCell.X), Math.Min(w.StartCell.Y, w.EndCell.Y)); Index2D end = new Index2D(Math.Max(w.StartCell.X, w.EndCell.X), Math.Max(w.StartCell.Y, w.EndCell.Y)); List <Tile> tiles = new List <Tile>(); if (dontRemove || Remove(w)) { List <Tile> ts; //place Left wall Remove(new Wall(new Index2D(start.X, start.Y + 1), new Index2D(start.X, end.Y - 1), Orientations.Left, TileTypes.SideWall, w.Theme), out ts, true); //for some reson foreach doesn't work here for (int i = 0; i < ts.Count; i++) { tiles.Add(ts[i]); } //place right wall Remove(new Wall(new Index2D(end.X, start.Y + 1), new Index2D(end.X, end.Y - 1), Orientations.Right, TileTypes.SideWall, w.Theme), out ts, true); //for some reson foreach doesn't work here for (int i = 0; i < ts.Count; i++) { tiles.Add(ts[i]); } //place Top wall Remove(new Wall(new Index2D(start.X + 1, start.Y), new Index2D(end.X - 1, start.Y), Orientations.Down, TileTypes.Wall, w.Theme), out ts, true); //for some reson foreach doesn't work here for (int i = 0; i < ts.Count; i++) { tiles.Add(ts[i]); } //place Top wall Remove(new Wall(new Index2D(start.X + 1, end.Y), new Index2D(end.X - 1, end.Y), Orientations.Down, TileTypes.Bottom, w.Theme), out ts, true); //for some reson foreach doesn't work here for (int i = 0; i < ts.Count; i++) { tiles.Add(ts[i]); } //place corners //TL Tile t = new Tile() { Type = TileTypes.Corner, Theme = w.Theme, Traversable = false, Orientation = Orientations.Left, GridCell = start, }; tiles.Add(t); Remove(t, t.GridCell.X, t.GridCell.Y); //TR t = new Tile() { Type = TileTypes.Corner, Theme = w.Theme, Traversable = false, Orientation = Orientations.Down, GridCell = new Index2D(end.X, start.Y) }; tiles.Add(t); Remove(t, t.GridCell.X, t.GridCell.Y); //BL t = new Tile() { Type = TileTypes.Corner, Theme = w.Theme, Traversable = false, Orientation = Orientations.Up_Left, GridCell = new Index2D(start.X, end.Y) }; tiles.Add(t); Remove(t, t.GridCell.X, t.GridCell.Y); //BR t = new Tile() { Type = TileTypes.Corner, Theme = w.Theme, Traversable = false, Orientation = Orientations.Up, GridCell = new Index2D(end.X, end.Y) }; tiles.Add(t); Remove(t, t.GridCell.X, t.GridCell.Y); } Tiles = tiles; }
/// <summary> /// Determines what an object is and adds it to the level /// </summary> /// <param name="obj">Object we want to split and add</param> internal List <Tile> Add(LevelPart obj, bool dontAdd = false) { List <Tile> tiles = new List <Tile>(); //deterime what it is if (obj is Room) { Room r = obj as Room; if (dontAdd || Add(r)) { //we're going to be getting them a lot otherwise Index2D start = new Index2D(Math.Min(r.StartCell.X, r.EndCell.X), Math.Min(r.StartCell.Y, r.EndCell.Y)); Index2D end = new Index2D(Math.Max(r.StartCell.X, r.EndCell.X), Math.Max(r.StartCell.Y, r.EndCell.Y)); List <Tile> t; Add(new BorderWalls(r), out t, true); //for some reson foreach doesn't work here for (int i = 0; i < t.Count; i++) { tiles.Add(t[i]); } t = new List <Tile>(); Add(new Floor(r), out t, true); //for some reson foreach doesn't work here for (int i = 0; i < t.Count; i++) { tiles.Add(t[i]); } } } else if (obj is BorderWalls) { List <Tile> t = new List <Tile>(); BorderWalls b = obj as BorderWalls; /// \todo Make this instead spit out a wall if (!(b.StartCell.X == b.EndCell.X || b.StartCell.Y == b.EndCell.Y)) { Add(b, out t, dontAdd); } //for some reson foreach doesn't work here for (int i = 0; i < t.Count; i++) { tiles.Add(t[i]); } } else if (obj is Wall) { List <Tile> t; Add(obj as Wall, out t, dontAdd); //for some reson foreach doesn't work here for (int i = 0; i < t.Count; i++) { tiles.Add(t[i]); } } else if (obj is Floor) { List <Tile> t; Add(obj as Floor, out t, dontAdd); //for some reson foreach doesn't work here for (int i = 0; i < t.Count; i++) { tiles.Add(t[i]); } } return(tiles); }
void Level_MouseDown(object sender, MouseButtonEventArgs e) { //do some handling here for end of room that skips the rest if (SelectedTile != null && SelectedTile.IsSpecialObject) { if (e.MouseDevice.LeftButton == MouseButtonState.Pressed) { if (SelectedObject == null) { GridCell = GetCell(e.GetPosition(Level)); Index2D i = new Index2D(GridCell.X, GridCell.Y); // fill the pieces if (SelectedTile.Name == "Room") { SelectedObject = new Room(i) { FloorType = SelectedTile.FloorType, }; } else if (SelectedTile.Name == "Walls") { SelectedObject = new BorderWalls(i) { FloorType = SelectedTile.FloorType, }; } else if (SelectedTile.Name == "Wall") { SelectedObject = new Wall(i) { FloorType = SelectedTile.FloorType, }; } else if (SelectedTile.Name == "Floor") { SelectedObject = new Floor(i) { FloorType = SelectedTile.FloorType, }; } } else//here we complete things for the object { GridCell=GetCell(e.GetPosition(Level)); SelectedObject.EndCell = new Index2D(GridCell.X, GridCell.Y); //determine what it is List<Tile> tiles = ToListTile(TileMap.Add(SelectedObject)); foreach (Tile t in tiles) { Grid.SetColumn(t, t.GridCell.X); Grid.SetRow(t, t.GridCell.Y); This.mainWindow.Level.Children.Add(t); } SelectedObject = null; } } else if (e.MouseDevice.RightButton == MouseButtonState.Pressed) { } } else { if (e.MouseDevice.LeftButton == MouseButtonState.Pressed) { if (SelectedTile != null) { GridCell = GetCell(e.GetPosition(Level)); FirstClick = true; AddTile(GridCell); } } else if (e.MouseDevice.RightButton == MouseButtonState.Pressed) { if (ClearTile) { GridCell = GetCell(e.GetPosition(Level)); RemoveTile(GridCell); FirstClick = true; } CancelSelection = true; } } }