Exemplo n.º 1
0
        public void Update()
        {
            PlaySound = false;

            if (Direction == SnakeDirection.Stop)
            {
                return;
            }

            var head = new Point((Point)SnakePosition[0]);
            var tail = new Point((Point)SnakePosition[SnakePosition.Count - 1]);

            if (Direction == SnakeDirection.Left)
            {
                head.X--;
            }
            if (Direction == SnakeDirection.Right)
            {
                head.X++;
            }
            if (Direction == SnakeDirection.Up)
            {
                head.Y--;
            }
            if (Direction == SnakeDirection.Down)
            {
                head.Y++;
            }

            for (int i = 0; i < SnakePosition.Count - 1; i++)
            {
                SnakePosition[SnakePosition.Count - 1 - i] = new Point((Point)SnakePosition[SnakePosition.Count - 2 - i]);
            }

            SnakePosition[0] = head;

            if (IsCellEmpty(head.X, head.Y, true) == false)
            {
                Reset();
            }

            if (head.X == FoodPosition.X && head.Y == FoodPosition.Y)
            {
                SnakePosition.Add(tail);
                UpdateFood();
                PlaySound = true;
            }
        }