Exemplo n.º 1
0
        private void MoveSnakeBody()
        {
            Point part = new Point();

            if (SnakeParts.Count() > 1)
            {
                foreach (Image image in SnakeParts)
                {
                    if (image == SnakeParts.First())
                    {
                    }
                    else if (image == SnakeParts[1])
                    {
                        part = new Point(Canvas.GetLeft(SnakeParts[1]), Canvas.GetTop(SnakeParts[1]));

                        Canvas.SetLeft(SnakeParts[1], Canvas.GetLeft(SnakeParts.First()));
                        Canvas.SetTop(SnakeParts[1], Canvas.GetTop(SnakeParts.First()));
                    }
                    else
                    {
                        Point tempPos = new Point(Canvas.GetLeft(image), Canvas.GetTop(image));

                        Canvas.SetLeft(image, part.X);
                        Canvas.SetTop(image, part.Y);

                        part = tempPos;
                    }
                }
            }
        }
Exemplo n.º 2
0
 private void CheckSnake()
 {
     foreach (Image part in SnakeParts)
     {
         if (part != SnakeParts.First())
         {
             if (Canvas.GetTop(part) == _posY && Canvas.GetLeft(part) == _posX)
             {
                 StopGame();
             }
         }
     }
 }