private void PlaceRoom(IMap map, Rectangle room) { for (int x = room.X - 1; x < room.X + room.Width + 1; x++) { for (int y = room.Y - 1; y < room.Y + room.Height + 1; y++) { var point = new Point(x, y); if (!map.InBounds(point)) { continue; } if (y == room.Y - 1) { map.GetCellAt(point).Type = CellType.RoomWallHorizontal; } else if (y == room.Y + room.Height) { map.GetCellAt(point).Type = CellType.RoomWallHorizontal; } else if (x == room.X - 1 || x == room.X + room.Width) { map.GetCellAt(point).Type = CellType.RoomWallVertical; } else { map.SetWalkable(point, true); map.SetTransparent(point, true); map.GetCellAt(new Point(x, y)).Type = CellType.RoomFloor; } } } }
public void SetUpTestCase() { Contour currentContour = new Contour(Contours.Count + 1); Contours.Add(currentContour); Point pt1 = new Point(0, 0); pt1.T = 0; currentContour.Add(pt1); Point pt2 = new Point(100, 0); pt2.T = 100; currentContour.Add(pt2); Point pt3 = new Point(0, 100); pt3.T = 0; currentContour.Add(pt3); //Point pt4 = new Point(0, 100); //pt4.T = 0; //currentContour.Add(pt4); //Point pt5 = new Point(0, 40); //pt5.T = 1; //currentContour.Add(pt5); currentContour.Add(pt1); }
public void CarveMaze(Point startingPoint) { var section = new MazeSection(startingPoint, ConsoleColor.White, true); Sections.Add(section); Carve(startingPoint, section); CleanUpDeadEnds(); }
private bool IsValid(Point point, Direction dir, out bool foundRoom) { foundRoom = false; if (!map.InBounds(point)) { return(false); } if (map.GetCellAt(point).Type != CellType.Wall) { return(false); } if (visitedPoints.Contains(point)) { return(false); } //var point = point.Increment(dir); // Don't break walls between corridors var adjacent = (dir switch { Direction.Up => // Check E, W, N new List <Point> { point.Right(), point.Left(), point.Up() }, Direction.Down => // Check E, W, S new List <Point> { point.Right(), point.Left(), point.Down() }, Direction.Right => // Check N, E, S new List <Point> { point.Up(), point.Right(), point.Down() }, Direction.Left => // Check W, N, S new List <Point> { point.Left(), point.Up(), point.Down(), }, _ => throw new NotImplementedException() }).Where(a => map.InBounds(a));
public Point GetNextStep(Actor actor, List <Actor> actors, Point target) { var path = pathFinder.FindPath(actor.Location, target, map, ValidStep); var step = path[1]; bool ValidStep <TCell>(TCell cell, TCell destination) where TCell : ICell { var reachedDestination = cell.Location.X == destination.Location.X && cell.Location.Y == destination.Location.Y; var cellIsOccupied = actors.Any(a => a != actor && a.Location == new Point(cell.Location.X, cell.Location.Y)); return(reachedDestination || (map.IsWalkable(cell.Location) && !cellIsOccupied)); } return(new Point(step.Location.X, step.Location.Y)); }
private void SpawnMonster(Room room, IMap map) { var monsterType = GetMonsterType(map.Level); Point location; do { var x = Rnd.Next(room.Bounds.X, room.Bounds.Right); var y = Rnd.Next(room.Bounds.Y, room.Bounds.Bottom); location = new Point(x, y); }while (map.GameObjects.Any(g => g.Location == location)); map.Actors .Add(new Monster(monsterType, location, new RogueSharpFov(map))); }
private void Carve(Point point, MazeSection?section) { visitedPoints.Add(point); map.SetWalkable(point, true); map.SetTransparent(point, true); map.GetCellAt(point).Type = CellType.Maze; if (section == null) { var sectionColor = new ConsoleColor[] { ConsoleColor.Magenta, ConsoleColor.Yellow, ConsoleColor.Blue, ConsoleColor.Red, ConsoleColor.Green }[rnd.Next(0, 5)]; section = new MazeSection(point, ConsoleColor.DarkGray); Sections.Add(section); } var directions = new List <Direction> { Direction.Right, Direction.Left, Direction.Up, Direction.Down } .OrderBy(x => Guid.NewGuid()); foreach (var dir in directions) { var nextPoint = point.Increment(dir); if (IsValid(nextPoint, dir, out var foundRoom)) { section.Points.Add(nextPoint); var adjacentRooms = GetAdjacentRooms(point); section.AdjacentRooms = section.AdjacentRooms.Union(adjacentRooms) .ToList(); if (section.AdjacentRooms.Count > 2) { Carve(nextPoint, null); } else { Carve(nextPoint, section); } } } //Draw(); }
private void drawLine(Pen pen, Point pt1, Point pt2) { //Ekaterina _imageBuffer.Graphics.DrawLine(pen, pt1.X, _pictureBox.Height - pt1.Y, pt2.X, _pictureBox.Height - pt2.Y); //end Ekaterina }
public void SetUpTestCase() { Contour currentContour = new Contour(Contours.Count + 1); Contours.Add(currentContour); Point pt1 = new Point(0, 0); pt1.T = 0; currentContour.Add(pt1); Point pt2 = new Point(100, 0); pt2.T = 100; currentContour.Add(pt2); Point pt3 = new Point(0, 100); pt3.T = 0; currentContour.Add(pt3); //Point pt4 = new Point(0, 100); //pt4.T = 0; //currentContour.Add(pt4); //Point pt5 = new Point(0, 40); //pt5.T = 1; //currentContour.Add(pt5); currentContour.Add(pt1); }
public void PointsInputHandler(object sender, MouseEventArgs e) { Contour currentContour = Contours.FirstOrDefault(x => !x.IsCompleted); if (currentContour == null){ currentContour = new Contour(Contours.Count + 1); Contours.Add(currentContour); } var newPoint = new Point(e.X, _drawer.CanvasHeight - e.Y){Index = _lastPointIndex + 1}; if (currentContour.Head == null) { currentContour.Add(newPoint); _drawer.DrawPoints(Pens.Black, newPoint); //Ekaterina _drawer.RefreshImage(); //end Ekaterina _lastPointIndex++; } else{ if (currentContour.Tail == null){ var newLineSegment = new LineSegment(currentContour.Head, newPoint); if (Contours.Where(x => x != currentContour).Any(x => x.IntersectsWithLineSegment(newLineSegment, IntersectionCheckOptions.WithEdgePoints)) || currentContour.IntersectsWithLineSegment(newLineSegment, IntersectionCheckOptions.WithoutEdgePoints)){ MessageBox.Show(ErrorMessageBoxMessage, ErrorMessageBoxTitle); } else { currentContour.Add(newPoint); _drawer.DrawLineSegments(Pens.Black, newLineSegment); _lastPointIndex++; } } else{ var newLineSegment = new LineSegment(currentContour.Tail, newPoint); if (Contours.Where(x => x != currentContour).Any(x => x.IntersectsWithLineSegment(newLineSegment, IntersectionCheckOptions.WithEdgePoints)) || currentContour.IntersectsWithLineSegment(newLineSegment, IntersectionCheckOptions.WithoutEdgePoints)) { MessageBox.Show(ErrorMessageBoxMessage, ErrorMessageBoxTitle); } else{ currentContour.Add(newPoint); if (!currentContour.IsCompleted) { _drawer.DrawLineSegments(Pens.Black, newLineSegment); _lastPointIndex++; } else { _drawer.DrawLineSegments(Pens.Black, new LineSegment(currentContour.Tail, currentContour.Head)); } } } } if (currentContour.IsCompleted){ _tabControlHelper.CreatePageForContour(currentContour); } }
public void PointsInputHandler(object sender, MouseEventArgs e) { Contour currentContour = Contours.FirstOrDefault(x => !x.IsCompleted); if (currentContour == null) { currentContour = new Contour(Contours.Count + 1); Contours.Add(currentContour); } var newPoint = new Point(e.X, _drawer.CanvasHeight - e.Y) { Index = _lastPointIndex + 1 }; if (currentContour.Head == null) { currentContour.Add(newPoint); _drawer.DrawPoints(Pens.Black, newPoint); //Ekaterina _drawer.RefreshImage(); //end Ekaterina _lastPointIndex++; } else { if (currentContour.Tail == null) { var newLineSegment = new LineSegment(currentContour.Head, newPoint); if (Contours.Where(x => x != currentContour).Any(x => x.IntersectsWithLineSegment(newLineSegment, IntersectionCheckOptions.WithEdgePoints)) || currentContour.IntersectsWithLineSegment(newLineSegment, IntersectionCheckOptions.WithoutEdgePoints)) { MessageBox.Show(ErrorMessageBoxMessage, ErrorMessageBoxTitle); } else { currentContour.Add(newPoint); _drawer.DrawLineSegments(Pens.Black, newLineSegment); _lastPointIndex++; } } else { var newLineSegment = new LineSegment(currentContour.Tail, newPoint); if (Contours.Where(x => x != currentContour).Any(x => x.IntersectsWithLineSegment(newLineSegment, IntersectionCheckOptions.WithEdgePoints)) || currentContour.IntersectsWithLineSegment(newLineSegment, IntersectionCheckOptions.WithoutEdgePoints)) { MessageBox.Show(ErrorMessageBoxMessage, ErrorMessageBoxTitle); } else { currentContour.Add(newPoint); if (!currentContour.IsCompleted) { _drawer.DrawLineSegments(Pens.Black, newLineSegment); _lastPointIndex++; } else { _drawer.DrawLineSegments(Pens.Black, new LineSegment(currentContour.Tail, currentContour.Head)); } } } } if (currentContour.IsCompleted) { _tabControlHelper.CreatePageForContour(currentContour); } }
private int getXOffset(Point pt) { return pt.X < _pictureBox.Width / 2 ? 2 : -10; }
private void fillTriangle(Brush brush, Point[] trianglePoints) { System.Drawing.Point[] drawingPoints = { new System.Drawing.Point(trianglePoints[0].X, _pictureBox.Height - trianglePoints[0].Y), new System.Drawing.Point(trianglePoints[1].X, _pictureBox.Height - trianglePoints[1].Y), new System.Drawing.Point(trianglePoints[2].X, _pictureBox.Height - trianglePoints[2].Y)}; _imageBuffer.Graphics.FillPolygon(brush, drawingPoints); }
private void drawLine(Pen pen, Point pt1, Point pt2) { //Ekaterina _imageBuffer.Graphics.DrawLine(pen, pt1.X, _pictureBox.Height - pt1.Y, pt2.X, _pictureBox.Height - pt2.Y); //end Ekaterina }
private List <Room> GetAdjacentRooms(Point point) { return(map.Rooms.Where(r => Rectangle.Inflate(r.Bounds, 3, 3).Contains(new System.Drawing.Point(point.X, point.Y))) .ToList()); }
private int getXOffset(Point pt) { return(pt.X < _pictureBox.Width / 2 ? 2 : -10); }
private Weapon SpawnWeapon(Point location, int level, Random rnd) { var weaponType = GetWeaponType(level, rnd); return(new Weapon(location, weaponType)); }
public Contour GetSingleContour() { if (Contours.Count == 0) { throw new Exception("Контуры отсутствуют"); } if (!AllContoursAreCompleted) { throw new Exception("Все контуры должны быть замкнуты!"); } var boundingBoxes = new Dictionary <int, BoundingBox>(); for (int i = 0; i < Contours.Count; i++) { boundingBoxes.Add(i, Contours[i].GetBoundingBox()); } var largestBox = boundingBoxes.FirstOrDefault(x => boundingBoxes.Where(y => y.Key != x.Key).All(y => x.Value.Contains(y.Value))); var restBoxes = boundingBoxes.Where(x => x.Key != largestBox.Key).ToArray(); if (largestBox.Value == null) { throw new Exception("Контуры не образуют единой области. Дальнейшие вычисления невозможны"); } if (restBoxes.Any(x => restBoxes.Where(y => y.Key != x.Key).Any(y => x.Value.Contains(y.Value)))) { throw new Exception("Вложенность дырок недопустима. Дальнейшие вычисления невозможны"); } var largestContour = Contours[largestBox.Key]; largestContour.OrientCounterclockwise(); for (int i = 0; i < Contours.Count; i++) { if (i != largestBox.Key) { var contour = Contours[i]; contour.OrientClockwise(); var nearestPoints = largestContour.ToDictionary(x => x, x => contour.ToDictionary(y => y, y => Math.Sqrt(Math.Pow(x.X - y.X, 2) + Math.Pow(x.Y - y.Y, 2))).OrderBy(r => r.Value).First()). OrderBy(r => r.Value.Value).First(); int largeContourPointIndex = nearestPoints.Key.Index; int contourPointIndex = nearestPoints.Value.Key.Index; for (int j = 0; j < contour.Count - contourPointIndex + 1; j++) { Point pt = contour[contourPointIndex - 1 + j].Clone(); pt.Index = largeContourPointIndex + 1 + j; largestContour.Insert(pt.Index - 1, pt); } for (int j = 0; j < contourPointIndex; j++) { Point pt = contour[j].Clone(); pt.Index = largeContourPointIndex + contour.Count - contourPointIndex + j + 2; largestContour.Insert(pt.Index - 1, pt); } Point self = largestContour[largeContourPointIndex - 1].Clone(); int offset = self.Index + contour.Count + 2; self.Index = offset; largestContour.Insert(self.Index - 1, self); for (int j = offset; j < largestContour.Count; j++) { largestContour[j].Index = j + 1; } } } largestContour.Index = 1; Contours.Clear(); Contours.Add(largestContour); return(largestContour); }