Ejemplo n.º 1
0
        private void GenNewSnakeNode()
        {
            SnakeNode snakeNode = null;

            switch (Direct)
            {
            case Direction.UP:
                snakeNode = new SnakeNode(new Point(SnakeNodes[SnakeHead]._pos.X,
                                                    SnakeNodes[SnakeHead]._pos.Y - 1));
                break;

            case Direction.DOWN:
                snakeNode = new SnakeNode(new Point(SnakeNodes[SnakeHead]._pos.X,
                                                    SnakeNodes[SnakeHead]._pos.Y + 1));
                break;

            case Direction.LEFT:
                snakeNode = new SnakeNode(new Point(SnakeNodes[SnakeHead]._pos.X - 1,
                                                    SnakeNodes[SnakeHead]._pos.Y));
                break;

            case Direction.RIGHT:
                snakeNode = new SnakeNode(new Point(SnakeNodes[SnakeHead]._pos.X + 1,
                                                    SnakeNodes[SnakeHead]._pos.Y));
                break;
            }

            if (snakeNode != null)
            {
                SnakeNodes.Insert(0, snakeNode);
                myCanvas.Children.Add(SnakeNodes[0]._rect);
            }
        }
Ejemplo n.º 2
0
        private void UpdateSnakeNodes()
        {
            foreach (var snakeNode in SnakeNodes)
            {
                if (snakeNode == Head.Value)
                {
                    continue;
                }

                var currentNode = SnakeNodes.Find(snakeNode);
                var nextNode    = currentNode?.Next?.Value;

                if (snakeNode.Column < nextNode?.Column)
                {
                    snakeNode.Column += 1;
                }
                if (snakeNode.Column > nextNode?.Column)
                {
                    snakeNode.Column -= 1;
                }
                if (snakeNode.Row < nextNode?.Row)
                {
                    snakeNode.Row += 1;
                }
                if (snakeNode.Row > nextNode?.Row)
                {
                    snakeNode.Row -= 1;
                }
            }
        }
Ejemplo n.º 3
0
        private void ClearSnakeNodes()
        {
            if (SnakeNodes.Any())
            {
                SnakeNodes.Clear();
            }

            if (SnakeObjects.Any())
            {
                SnakeObjects.Clear();
            }
        }