/// <summary> /// Вызов события разрушения стены /// </summary> /// <param name="Wall">Стена</param> protected void OnWallDestroying(MapWallState Wall) { if (WallDestroying != null) { WallDestroying(this, this, new MapWallEventArgs(Wall)); } }
/// <summary> /// Вызов события разрушения стены /// </summary> /// <param name="Cell">Клетка, в которой расположена стена</param> /// <param name="Wall">Стена</param> protected void OnWallDestroyed(MapCellState Cell, MapWallState Wall) { if (WallDestroyed != null) { WallDestroyed(this, Cell, new MapWallEventArgs(Wall)); } }
/// <summary> /// Состояние клетки карты /// </summary> /// <param name="Cell">Клетка</param> /// <param name="Point">Координаты</param> public MapCellState(MapCell Cell, MapPoint Point) { if (Cell == null) { throw new ArgumentNullException("Cell", "Cell of MapCellState cannot be null"); } this.Point = Point; this.Cell = Cell; this.Place = (Cell.Place != null) ? new MapPlaceState(Cell.Place) : null; if (Cell.Walls != null) { foreach (KeyValuePair <MapDirection, MapWall> wall in Cell.Walls) { if (wall.Value == null) { continue; } MapWallState wallState = new MapWallState(wall.Value, wall.Key); wallState.Destroying += (sender, args) => { OnWallDestroying(args.Wall); }; wallState.Destroyed += (sender, args) => { OnWallDestroyed(args.Wall); }; this.SetWall(wall.Key, wallState); } } }
/// <summary> /// Вызов события разрушения стены /// </summary> /// <param name="Wall">Стена</param> protected void OnWallDestroyed(MapWallState Wall) { if (Wall.Wall == null) { if (this.HasWall(Wall)) { this.RemoveWall(Wall.Direction); } } if (WallDestroyed != null) { WallDestroyed(this, this, new MapWallEventArgs(Wall)); } }
/// <summary> /// Задать стену по направлению /// </summary> /// <param name="Direction">Направление</param> /// <param name="Wall">Стена</param> public void SetWall(MapDirection Direction, MapWallState Wall) { if (Direction == Maps.MapDirection.North) { NorthWall = Wall; } if (Direction == Maps.MapDirection.South) { SouthWall = Wall; } if (Direction == Maps.MapDirection.West) { WestWall = Wall; } if (Direction == Maps.MapDirection.East) { EastWall = Wall; } }
/// <summary> /// Проходимость с определённой стороны /// </summary> /// <param name="Direction">Сторона</param> /// <returns>Проходимость</returns> public float GetPassbilityByDirection(MapDirection Direction) { float passablity = (this.Place != null) ? this.Place.Passability : 1; MapWallState wall = GetWall(Direction); if (wall != null) { passablity -= wall.Passability; } foreach (MapActiveObjectState active in ActiveObjects) { passablity -= active.Passability; } if (passablity < 0) { passablity = 0; } return(passablity); }
/// <summary> /// Состояние клетки карты /// </summary> /// <param name="Cell">Клетка</param> /// <param name="Point">Координаты</param> public MapCellState(MapCell Cell, MapPoint Point) { if (Cell == null) throw new ArgumentNullException("Cell", "Cell of MapCellState cannot be null"); this.Point = Point; this.Cell = Cell; this.Place = (Cell.Place != null) ? new MapPlaceState(Cell.Place) : null; if (Cell.Walls != null) { foreach (KeyValuePair<MapDirection, MapWall> wall in Cell.Walls) { if (wall.Value == null) continue; MapWallState wallState = new MapWallState(wall.Value, wall.Key); wallState.Destroying += (sender, args) => { OnWallDestroying(args.Wall); }; wallState.Destroyed += (sender, args) => { OnWallDestroyed(args.Wall); }; this.SetWall(wall.Key, wallState); } } }
/// <summary> /// Есть ли данная стена /// </summary> /// <param name="Wall">Стена</param> /// <returns>Есть ли стена</returns> public bool HasWall(MapWallState Wall) { return(Walls.ContainsValue(Wall)); }
/// <summary> /// Вызов события разрушения стены /// </summary> /// <param name="Cell">Клетка, в которой расположена стена</param> /// <param name="Wall">Стена</param> protected void OnWallDestroying(MapCellState Cell, MapWallState Wall) { if (WallDestroying != null) WallDestroying(this, Cell, new MapWallEventArgs(Wall)); }
/// <summary> /// Аргумент - стена /// </summary> /// <param name="Wall">Стена</param> public MapWallEventArgs(MapWallState Wall) { this.Wall = Wall; }
/// <summary> /// Вызов события разрушения стены /// </summary> /// <param name="Wall">Стена</param> protected void OnWallDestroyed(MapWallState Wall) { if (Wall.Wall == null) { if (this.HasWall(Wall)) this.RemoveWall(Wall.Direction); } if (WallDestroyed != null) WallDestroyed(this, this, new MapWallEventArgs(Wall)); }
/// <summary> /// Задать стену по направлению /// </summary> /// <param name="Direction">Направление</param> /// <param name="Wall">Стена</param> public void SetWall(MapDirection Direction, MapWallState Wall) { if (Direction == Maps.MapDirection.North) NorthWall = Wall; if (Direction == Maps.MapDirection.South) SouthWall = Wall; if (Direction == Maps.MapDirection.West) WestWall = Wall; if (Direction == Maps.MapDirection.East) EastWall = Wall; }
/// <summary> /// Есть ли данная стена /// </summary> /// <param name="Wall">Стена</param> /// <returns>Есть ли стена</returns> public bool HasWall(MapWallState Wall) { return Walls.ContainsValue(Wall); }
private FrameworkElement RenderWallCorner(MapWallState wall1, MapWallState wall2, Rect area) { if (wall1 == null) return null; if (wall1.Wall == null) return null; if (wall2 == null) return null; if (wall2.Wall == null) return null; if (wall1.Wall.Id != wall2.Wall.Id) return null; MapImage cornerImage = wall1.Wall.ImageCorner; if (cornerImage == null) return null; double wallWidth = area.Width * WallPadding; double wallHeight = area.Height * WallPadding; MapImageWPF imageSource = new MapImageWPF(cornerImage); double imageWidth = wallWidth; double imageHeight = wallHeight; Image image = new Image { Source = imageSource.Image, Width = imageWidth, Height = imageHeight, Stretch= Stretch.Uniform}; image.RenderTransformOrigin = new Point(0.5, 0.5); if ((wall1.Direction == MapDirection.North) && (wall2.Direction == MapDirection.West)) { Canvas.SetLeft(image, area.Left); Canvas.SetTop(image, area.Top); } if ((wall1.Direction == MapDirection.North) && (wall2.Direction == MapDirection.East)) { Canvas.SetLeft(image, area.Left + area.Width - imageWidth); Canvas.SetTop(image, area.Top); image.RenderTransform = new RotateTransform(90); } if ((wall1.Direction == MapDirection.South) && (wall2.Direction == MapDirection.West)) { Canvas.SetLeft(image, area.Left); Canvas.SetTop(image, area.Top + area.Height - imageHeight); image.RenderTransform = new RotateTransform(-90); } if ((wall1.Direction == MapDirection.South) && (wall2.Direction == MapDirection.East)) { Canvas.SetLeft(image, area.Left + area.Width - imageWidth); Canvas.SetTop(image, area.Top + area.Height - imageHeight); image.RenderTransform = new RotateTransform(180); } return image; }
private FrameworkElement RenderWall(MapWallState wall, Rect area) { if (wall == null) return null; if (wall.Wall == null) return null; MapImageWPF imageSource = new MapImageWPF(wall.CurrentImage); Image image = new Image { Source = imageSource.Image }; double wallWidth = area.Width * WallPadding; double wallHeight = area.Height * WallPadding; double imageWidth = area.Width; double imageHeight = wallHeight; image.Stretch = Stretch.Fill; if (wall.Direction == MapDirection.North) { Canvas.SetLeft(image, area.Left); Canvas.SetTop(image, area.Top); image.Width = imageWidth; image.Height = imageHeight; } if (wall.Direction == MapDirection.South) { Canvas.SetLeft(image, area.Left); Canvas.SetTop(image, area.Top + area.Height); image.Width = imageWidth; image.Height = imageHeight; image.RenderTransformOrigin = new Point(0.5, 0); image.RenderTransform = new RotateTransform(-180); } if (wall.Direction == MapDirection.West) { Canvas.SetLeft(image, area.Left); Canvas.SetTop(image, area.Top + imageWidth); image.Width = imageWidth; image.Height = imageHeight; image.RenderTransformOrigin = new Point(0, 0); image.RenderTransform = new RotateTransform(-90); } if (wall.Direction == MapDirection.East) { Canvas.SetLeft(image, area.Left); Canvas.SetTop(image, area.Top + imageWidth); image.Width = imageWidth; image.Height = imageHeight; image.RenderTransformOrigin = new Point(1, 0); image.RenderTransform = new RotateTransform(90); } return image; }
/// <summary> /// Аргумент - стена /// </summary> /// <param name="Wall">Стена</param> public MapWallEventArgs(MapWallState Wall) { this.Wall = Wall; }