Ejemplo n.º 1
0
        public static void Initialize()
        {
            thisEvolution = new Evolution();
            thisEvolution.Start();

            Loading = true;


            Random RNG = new Random();

            EvolviMaxAmount    = 1f;
            EvolviLoadedAmount = 0;

            CurrentGeneration.Clear();

            for (int i = 0; i < evolviAmount; i++)
            {
                CurrentGeneration.Add(new Evolvi(new Vector2(RNG.Next(20, 2000 - 20), RNG.Next(20, 2000 - 20))));
            }

            CurrentFood.Clear();

            for (int i = 0; i < foodAmount; i++)
            {
                CurrentFood.Add(new Food(new Vector2(RNG.Next(20, 2000 - 20), RNG.Next(20, 2000 - 20))));

                Thread.Sleep(10);
            }

            Loading = false;
        }
Ejemplo n.º 2
0
        public int GetFoodDistance(Direction direction)
        {
            int FixNegative(int value) => value < 0 ? Math.Abs(value) * 2 : value;

            switch (direction)
            {
            case Direction.Left:
                return(FixNegative(SnakeHead.GetPosition().X - CurrentFood.GetPosition().X));

            case Direction.Right:
                return(FixNegative(CurrentFood.GetPosition().X - SnakeHead.GetPosition().X));

            case Direction.Up:
                return(FixNegative(SnakeHead.GetPosition().Y - CurrentFood.GetPosition().Y));

            case Direction.Down:
                return(FixNegative(CurrentFood.GetPosition().Y - SnakeHead.GetPosition().Y));

            default:
                throw new ArgumentOutOfRangeException(nameof(direction), direction, null);
            }
        }