예제 #1
0
 private void timer1_Tick(object sender, EventArgs e)
 {
     Refresh();
     Python.Move(Python);
     Python.IsEat(Python, F);
     Python.Complexity(Python, timer1);
     Python.Border(PB_Field);
     Python.DrawSnake(F.ParentGraphics);
     F.FoodDirectory(F);
     F.DrawFood(F.ParentGraphics);
     L_Score.Text = "Счёт: " + Convert.ToString(Python.snake.Count - 3);
 }
        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);
        }