Пример #1
0
        private Point getNextLoS(Point current)
        {
            Point[] adjPts   = getAdjacentPoints(current);
            Point   best     = adjPts[0];
            double  bestDist = DistanceBetween(best, end);

            for (int i = 1; i < adjPts.Length; i++)
            {
                if ((!TacticsGrid.GetInstance().CanTraverse(adjPts[i])) && (!adjPts[i].Equals(end)))
                {
                    continue;
                }
                double dist = DistanceBetween(adjPts[i], end);
                if (dist < bestDist)
                {
                    bestDist = dist;
                    best     = adjPts[i];
                }
            }
            if (!TacticsGrid.GetInstance().CanTraverse(best))
            {
                if (!best.Equals(end))
                {
                    throw new UnreachableDestinationException();
                }
            }
            if (bestDist > DistanceBetween(current, end))
            {
                throw new UnreachableDestinationException();
            }
            return(best);
        }
Пример #2
0
 public static TacticsGrid GetInstance()
 {
     if (instance == null)
     {
         instance = new TacticsGrid();
     }
     return(instance);
 }
Пример #3
0
 private void BuildDirectPath()
 {
     while (!IsComplete())
     {
         Point next = GetNextDirectStep();
         path.Push(next);
         this.obstructed = this.obstructed || TacticsGrid.GetInstance().CanTraverse(next);
     }
 }
Пример #4
0
 private void RemoveBlockedPaths(List <Node> nodes)
 {
     foreach (Node n in nodes)
     {
         if (!TacticsGrid.GetInstance().CanTraverse(n.pos))
         {
             nodes.Remove(n);
         }
     }
 }
Пример #5
0
        private void DrawMovementLine(Graphics g, Point p)
        {
            Stack <Point> path      = (new AStar(TacticsGrid.ConvertPointToGrid(p), state.GetDestination(this))).FindPath();
            int           moves     = GetMovementSpeed();
            Point         current   = p;
            Point         lastPoint = new Point(Int32.MinValue, Int32.MinValue);
            Pen           pen       = new Pen(Color.Red);

            pen.Width = 3;
            //while (moves-- >= 0 && path.Count > 0)
            while (path.Count > 0)
            {
                lastPoint = current;
                current   = path.Pop();
                g.DrawLine(pen, TacticsGrid.ConvertPointToGraphics(CenterPoint(lastPoint)), TacticsGrid.ConvertPointToGraphics(CenterPoint(current)));
            }
            pen.Dispose();
            pen       = new Pen(Color.Yellow);
            pen.Width = 3;
            Rectangle bound = new Rectangle(TacticsGrid.ConvertPointToGraphics(lastPoint), new Size(50, 50));

            g.DrawEllipse(pen, bound);
            pen.Dispose();
        }
Пример #6
0
 public bool Impassable()
 {
     return(!TacticsGrid.GetInstance().CanTraverse(pos));
 }
Пример #7
0
 static void Main()
 {
     Application.EnableVisualStyles();
     Application.SetCompatibleTextRenderingDefault(false);
     Application.Run(TacticsGrid.GetInstance());
 }