Beispiel #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);
            }
        }
Beispiel #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;
                }
            }
        }
Beispiel #3
0
        private void ClearSnakeNodes()
        {
            if (SnakeNodes.Any())
            {
                SnakeNodes.Clear();
            }

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