예제 #1
0
        public virtual bool FollowPath(FloorPlan plan)
        {
            int currentIndex = Path.FindIndex(p => p.X == X && p.Y == Y);

            if (currentIndex < Path.Count - 1)
            {
                Location nextPoint = Path[currentIndex + 1];
                var      tile      = plan.GetFloorTile(nextPoint);
                if (tile.Cost > 1)
                {
                    AttackTile(tile);
                    return(true);
                }
                else
                {
                    OldPoint = Point;
                    Point    = nextPoint;
                    return(true);
                }
            }
            else
            {
                return(false);
            }
        }
        public static string Print(this FloorPlan floorPlan, List <Location> path = null)
        {
            if (path == null)
            {
                path = new List <Location>();
            }

            var sb     = new StringBuilder();
            var maxRow = floorPlan.FloorTiles.Max(x => x.Y);
            var maxCol = floorPlan.FloorTiles.Max(x => x.X);

            for (int row = 0; row <= maxRow; row++)
            {
                for (int col = 0; col <= maxCol; col++)
                {
                    if (floorPlan.IsAgentOnTile(col, row))
                    {
                        sb.Append("@");
                    }
                    else if (path.Contains(new Location(col, row)))
                    {
                        sb.Append(path.IndexOf(new Location(col, row)).ToLetter());
                        //sb.Append("=");
                    }
                    else
                    {
                        var tile = floorPlan.GetFloorTile(col, row);
                        sb.Append(tile.Print());
                    }
                }
                sb.AppendLine();
            }
            string output = sb.ToString();


            return(output);
        }