Example #1
0
 public void Complexity(Snakes Python, Timer timer1)
 {
     if (Python.EatYourselve())
     {
         Python.snake.RemoveRange(Python.snake.Count - Python.snake.Count / 3, Python.snake.Count / 3);
     }
     if (Python.snake.Count % 5 == 0 && timer1.Interval > 50 && !complexity)
     {
         timer1.Interval -= 20;
         complexity       = true;
     }
 }
        private void timer1_Tick(object sender, EventArgs e)
        {
            Refresh();
            switch (Python.direct)
            {
            case Snakes.Directions.Up:
            {
                Python.prev_segment = new Rectangle(Python.snake[0].X, Python.snake[0].Y - 20, 20, 20);
            }
            break;

            case Snakes.Directions.Down:
            {
                Python.prev_segment = new Rectangle(Python.snake[0].X, Python.snake[0].Y + 20, 20, 20);
            }
            break;

            case Snakes.Directions.Left:
            {
                Python.prev_segment = new Rectangle(Python.snake[0].X - 20, Python.snake[0].Y, 20, 20);
            }
            break;

            case Snakes.Directions.Right:
            {
                Python.prev_segment = new Rectangle(Python.snake[0].X + 20, Python.snake[0].Y, 20, 20);
            }
            break;
            }
            for (int i = 0; i < Python.snake.Count; i++)
            {
                Python.segment      = Python.snake[i];
                Python.snake[i]     = Python.prev_segment;
                Python.prev_segment = Python.segment;
            }
            Python.DrawSnake(F.ParentGraphics);
            F.DrawFood(F.ParentGraphics);
            if (Math.Abs(Python.snake[0].X - F.food.X) <= 20 && Math.Abs(Python.snake[0].Y - F.food.Y) <= 20)
            {
                F.FoodExist = false;
                Python.snake.Add(new Rectangle(Python.snake[Python.snake.Count - 1].X + 20, Python.snake[Python.snake.Count - 1].Y + 20, 20, 20));
                F.DrawFood(F.ParentGraphics);
            }
            switch (F.FoodDir)
            {
            case Snakes.Directions.Up:
            {
                F.food = new Rectangle(F.food.X, F.food.Y - 5, 20, 20);
            }
            break;

            case Snakes.Directions.Down:
            {
                F.food = new Rectangle(F.food.X, F.food.Y + 5, 20, 20);
            }
            break;

            case Snakes.Directions.Left:
            {
                F.food = new Rectangle(F.food.X - 5, F.food.Y, 20, 20);
            }
            break;

            case Snakes.Directions.Right:
            {
                F.food = new Rectangle(F.food.X + 5, F.food.Y, 20, 20);
            }
            break;
            }
            if (Python.EatYourselve())
            {
                Python.snake.RemoveRange(Python.snake.Count - Python.snake.Count / 3, Python.snake.Count / 3);
            }
            Python.Border(PB_Field);
        }