Exemplo n.º 1
0
 private void InitSnake()
 {
     snake = new Snake();
     for(int i = 0; i < snake.Count; i++)
     {
         SnakeGrid.Children.Add(snake[i]);
     }
     bug = new Bug();
     SnakeGrid.Children.Add(bug);
     Score.Content = "Score: 0";
 }
Exemplo n.º 2
0
        private void Timer_Tick(object sender, EventArgs e)
        {
            snake.Move();
            BodyCollisionControl();
            if (EatControl())
            {
                //E' necessario per far si che non venga creato un nuovo insetto
                //sopra al precedente
                Thickness xPoint = bug.Margin;

                SnakeGrid.Children.Remove(bug);

                snake.Stretch();
                SnakeGrid.Children.Add(snake[snake.Count - 1]);

                {
                    bug = new Bug();
                } while (EatControl() && bug.Margin == xPoint);

                SnakeGrid.Children.Add(bug);
                Score.Content = "Score: " + snake.Score;
            }

            keyEnable = true;
        }