示例#1
0
 public static GrasTile GetTileSave(SimpleCords cords)
 {
     if (cords.X >= 0 && cords.X < width && cords.Y >= 0 && cords.Y < height)
     {
         GrasTile t = garden[cords.X, cords.Y];
         return(t);
     }
     return(null);
 }
示例#2
0
 private static void InitializeGarden()
 {
     for (int x = 0; x < garden.GetLength(0); x++)
     {
         for (int y = 0; y < garden.GetLength(1); y++)
         {
             garden[x, y] = new GrasTile(new SimpleCords(x, y));
         }
     }
 }
示例#3
0
        public static List <GrasTile> GetTilesAt(double x, double y, bool revert)
        {
            List <SimpleCords> posofTiles = new List <SimpleCords>();

            //revert = true;

            if (x % 1 == 0.5)
            {
                if (revert)
                {
                    posofTiles.Add(new SimpleCords((int)Math.Round(x + 0.5), (int)y));
                    posofTiles.Add(new SimpleCords((int)Math.Round(x - 0.5), (int)y));
                }
                else
                {
                    posofTiles.Add(new SimpleCords((int)Math.Round(x - 0.5), (int)y));
                    posofTiles.Add(new SimpleCords((int)Math.Round(x + 0.5), (int)y));
                }
            }
            if (y % 1 == 0.5)
            {
                if (revert)
                {
                    posofTiles.Add(new SimpleCords((int)x, (int)Math.Round(y + 0.5)));
                    posofTiles.Add(new SimpleCords((int)x, (int)Math.Round(y - 0.5)));
                }
                else
                {
                    posofTiles.Add(new SimpleCords((int)x, (int)Math.Round(y - 0.5)));
                    posofTiles.Add(new SimpleCords((int)x, (int)Math.Round(y + 0.5)));
                }
            }

            List <GrasTile> tiles = new List <GrasTile>();

            foreach (var item in posofTiles)
            {
                GrasTile t = GetTileSave(item);
                if (item != null)
                {
                    tiles.Add(t);
                }
            }
            return(tiles);
        }
示例#4
0
        // here is how the distributes of rotation works

        #endregion


        static void Main(string[] args)
        {
            // setup the GMU
            Console.BackgroundColor = ConsoleColor.Black;
            Console.ForegroundColor = ConsoleColor.White;

            GMU gmu = new GMU(height + 10, width + 10);

            FullScreenManager screen = new FullScreenManager(height, width, gmu.PlacePixels);

            PlaceImage(screen, 0, 0, BasicProvider.getInked(width, height, new PInfo('A', ConsoleColor.Black, ConsoleColor.White)));
            gmu.PrintFrame();

            // x , y
            garden = new GrasTile[width, height];

            InitializeGarden();

            mower = new Mower(10, 10, Math.PI * 115 / 180);

            ConsoleKeyInfo input;

            while ((!Console.KeyAvailable))
            {
                foreach (var item in garden)
                {
                    PlaceImage(screen, item.position.X, item.position.Y, BasicProvider.getInked(1, 1, item.getInfo()));
                }

                //gmu.PrintFrame();
                Debug.WriteLine("angle: " + mower.angle * 180 / Math.PI + "°");

                /*switch (input.Key.ToString())
                 * {
                 *  case "RightArrow":
                 *      //mower.angle = mower.angle + Math.PI / 16;
                 *      //mower.UpdateVectorFromAngle();
                 *      break;
                 *  case "LeftArrow":
                 *      //mower.angle = mower.angle - Math.PI / 16;
                 *      //mower.UpdateVectorFromAngle();
                 *      break;
                 *  case "A":
                 *
                 *      break;
                 *  case "W":
                 *
                 *      break;
                 *  case "D":
                 *
                 *      break;
                 *  default:
                 *      break;
                 * }*/

                PlaceImage(screen, (int)mower.posX, (int)mower.posY, BasicProvider.getInked(1, 1, new PInfo('O', ConsoleColor.White, ConsoleColor.Gray)));
                gmu.PrintFrame();
                Queue <GrasTile> cutTiles = CalculateMowerUntilNextStop(false);

                mower = new Mower(mower.posX, mower.posY, mower.angle);

                if (cutTiles.Count > 0)
                {
                    //cutTiles.Dequeue();
                }

                foreach (var item in cutTiles)
                {
                    PInfo i = new PInfo();
                    i.background = ConsoleColor.DarkGray;
                    PlaceImage(screen, item.position.X, item.position.Y, BasicProvider.getInked(1, 1, i));
                }
                gmu.PrintFrame();

                //System.Threading.Thread.Sleep(1500);

                /*if (Console.KeyAvailable)
                 * {
                 *  Console.ReadKey(true);
                 * }*/

                CalculateMowerUntilNextStop(true);
                while (cutTiles.Count > 0)
                {
                    GrasTile tile = cutTiles.Dequeue();
                    tile.Cut();
                    PlaceImage(screen, tile.position.X, tile.position.Y, BasicProvider.getInked(1, 1, tile.getInfo()));
                    System.Threading.Thread.Sleep(waitTime);
                    gmu.PrintFrame();
                }

                RePlaceAllTiles(screen, gmu);
            }

            Console.ReadKey(true);
        }