Пример #1
0
        /// <summary>
        /// Sets up the Starting Field
        /// </summary>
        public void SetupNewField()
        {
            var x = Math.Floor(CanvasWidth / 2d);
            var y = Math.Floor(CanvasHeight / 2d);

            CircleBodyParts.Add(new SnakeBodyPart(x, y));

            for (var i = gh.GetSnakeSize() - 1; i > 0; i--)
            {
                AddNewSnakeBodyPart();
            }
        }
Пример #2
0
        private bool AddNewSnakeBodyPart()
        {
            double newX     = 0;
            double newY     = 0;
            var    u        = CircleBodyParts.Count - 1;
            var    directon = gh.GetSnakeDirection();

            switch (directon)
            {
            case "Right":
                newX = CircleBodyParts[u].X + (SnakeBodyPart.SnakePartSize - 1);
                newY = CircleBodyParts[u].Y;
                break;

            case "Left":
                newX = CircleBodyParts[u].X - (SnakeBodyPart.SnakePartSize - 1);
                newY = CircleBodyParts[u].Y;
                break;

            case "Up":
                newX = CircleBodyParts[u].X;
                newY = CircleBodyParts[u].Y - (SnakeBodyPart.SnakePartSize - 1);
                break;

            case "Down":
                newX = CircleBodyParts[u].X;
                newY = CircleBodyParts[u].Y + (SnakeBodyPart.SnakePartSize - 1);
                break;
            }
            if ((newX <= 0 || newX >= CanvasWidth) || newY <= 0 || newY >= CanvasHeight)
            {
                GameOver();
                return(false);
            }
            else
            {
                CircleBodyParts.Add(new SnakeBodyPart(newX, newY));
                return(true);
            }
        }