Пример #1
0
        //public static void DisplayGrid(int[,] grid, City startingCity)
        //{
        //    for (int rowCtr = 0; rowCtr < grid.GetLength(0); rowCtr++)
        //    {
        //        for (int colCtr = 0; colCtr < grid.GetLength(1); colCtr++)
        //        {
        //            Console.ForegroundColor = ConsoleColor.White;
        //            int cell = grid[colCtr, rowCtr];
        //            if (cell > 0)
        //            {
        //                if (startingCity.NumberId == cell)
        //                    Console.ForegroundColor = ConsoleColor.Yellow;
        //                else
        //                    Console.ForegroundColor = ConsoleColor.Red;
        //                Console.Write(grid[colCtr, rowCtr].ToString());
        //                Console.ForegroundColor = ConsoleColor.White;
        //                Console.Write("-");
        //            }
        //            else
        //            {
        //                Console.Write("0-");
        //            }
        //        }
        //        Console.WriteLine("");
        //    }
        //}
        public static void DisplayGrid(int[,] grid, City startingCity, int pathCountToDisplay)
        {
            int curPathCount = 0;
            string curPointName = string.Empty;

            for (int rowCtr = 0; rowCtr < grid.GetLength(0); rowCtr++)
            {
                for (int colCtr = 0; colCtr < grid.GetLength(1); colCtr++)
                {
                    Console.ForegroundColor = ConsoleColor.White;

                    //------------------------------------------------------
                    bool isTravelPoint = IsTravelPoint(startingCity, colCtr, rowCtr);
                    //bool isTravelPoint = false;
                    //foreach (Point travelPoint in startingCity.TravelPoints)
                    //{
                    //    if (travelPoint.Name != curPointName && curPathCount <= pathCountToDisplay)
                    //    {
                    //        curPointName = travelPoint.Name;
                    //        curPathCount++;
                    //    }
                    //    if (travelPoint.X == colCtr && travelPoint.Y == rowCtr)
                    //    {
                    //        isTravelPoint = true;
                    //        break;
                    //    }
                    //}
                    //------------------------------------------------------

                    int cell = grid[colCtr, rowCtr];
                    if (cell > 0)
                    {
                        if (startingCity.NumberId == cell)
                            Console.ForegroundColor = ConsoleColor.Yellow;
                        else
                            Console.ForegroundColor = ConsoleColor.Red;

                        Console.Write(grid[colCtr, rowCtr].ToString());
                        Console.ForegroundColor = ConsoleColor.White;
                        Console.Write("-");
                    }
                    else
                    {
                        if (isTravelPoint)
                            Console.ForegroundColor = ConsoleColor.Green;
                        else
                            Console.ForegroundColor = ConsoleColor.White;

                        Console.Write("0-");
                    }
                }

                Console.WriteLine("");
            }
        }
Пример #2
0
        private CityDistance CalculateDistance(int yDiff, int xDiff, City startCity, City destinationCity, City beginningCity)
        {
            CityDistance cityDistance = new CityDistance();
            cityDistance.CityName = destinationCity.Name;

            //x,y comparison values to this city and the other city running count
            int xDiffCompare = 0;
            int yDiffCompare = 0;

            //list each 2 d movement point for grid display
            int xRunning = this.X;
            int yRunning = this.Y;

            throw new System.Exception("Find way to not let a movement point go through a city");

            while (true)
            {
                if (yDiffCompare == yDiff && xDiffCompare == xDiff)
                    break;

                //W
                if (xDiff > 0 && (yDiff == yDiffCompare))
                {
                    xDiffCompare++;
                    xRunning--;
                }
                //E
                else if (xDiff < 0 && (yDiff == yDiffCompare))
                {
                    xDiffCompare--;
                    xRunning++;
                }
                //N
                else if (yDiff > 0 && (xDiff == xDiffCompare))
                {
                    yDiffCompare++;
                    yRunning--;
                }
                //S
                else if (yDiff < 0 && (xDiff == xDiffCompare))
                {
                    yDiffCompare--;
                    yRunning++;
                }
                //NE
                else if (xDiff > 0 && yDiff > 0)
                {
                    xDiffCompare++;
                    yDiffCompare++;
                    xRunning--;
                    yRunning--;
                }
                //NW
                else if (xDiff < 0 && yDiff > 0)
                {
                    xDiffCompare--;
                    yDiffCompare++;
                    xRunning++;
                    yRunning--;
                }
                //SE
                else if (xDiff > 0 && yDiff < 0)
                {
                    xDiffCompare++;
                    yDiffCompare--;
                    xRunning--;
                    yRunning++;
                }
                //SW
                else if (xDiff < 0 && yDiff < 0)
                {
                    xDiffCompare--;
                    yDiffCompare--;
                    xRunning++;
                    yRunning++;
                }
                else
                {
                    throw new System.Exception("Unknown direction");
                }

                cityDistance.Distance++;
                cityDistance.TravelPoints.Add(new Point(xRunning, yRunning, startCity.Name + "-" + destinationCity.Name));
            }

            return cityDistance;
        }
Пример #3
0
        //TODO - comment these public methods
        public City Clone()
        {
            City newCity = new City(this.Name, this.X, this.Y, this.NumberId);
            newCity.AddedToGrid = this.AddedToGrid;

            //foreach (var steps in StepsToOtherCities)
            //{
            //    newCity.StepsToOtherCities.Add(steps.Key, steps.Value);
            //}

            return newCity;
        }
Пример #4
0
        //TODO - replace with linq query
        private static bool IsTravelPoint(City startingCity, int x, int y)
        {
            bool isTravelPnt = false;

            foreach (Point travelPoint in startingCity.TravelPoints)
            {
                if (travelPoint.X == x && travelPoint.Y == y)
                {
                    isTravelPnt = true;
                    break;
                }
            }

            return isTravelPnt;
        }