Ejemplo n.º 1
0
        public void MoveSnakeParts(LinkedList <SnakePart> snakeParts, MapManager mm)
        {
            LinkedListNode <SnakePart> snakeHead = snakeParts.Last;
            Tile destinationTile = mm.GetTileInFrontOfSnakePart(snakeHead.Value);
            Tile currentTile     = mm.GetTileWithItem(snakeParts.First.Value);

            mm.PlaceItemOnTile(currentTile, null);

            for (LinkedListNode <SnakePart> snakePartNode = snakeParts.First; snakePartNode != null;)
            {
                LinkedListNode <SnakePart> nextSnakePartNode = snakePartNode.Next;
                if (nextSnakePartNode != null)
                {
                    // Move snakePart forward to take the tile of the next snakePart
                    MoveSnakePartToTileOfNextSnakePart(mm, snakePartNode.Value, nextSnakePartNode.Value);
                }
                else
                {
                    //Moves snakehead to destination
                    MoveSnakeHeadToDestinationTile(mm, destinationTile, snakePartNode.Value);
                }
                snakePartNode = nextSnakePartNode;
            }
            if (ShouldGrow)
            {
                GrowSnake(mm);
            }
            HandleCollision(mm.GetTileInFrontOfSnakePart(snakeHead.Value));
        }
Ejemplo n.º 2
0
        public void AddSnakeToMap(MapManager mm)
        {
            SnakePart snakeTail = snakeParts.First();

            mm.PlaceItemOnTile(mm.GetCenterTile(), snakeTail);

            for (LinkedListNode <SnakePart> currentNode = snakeParts.First; currentNode != null;)
            {
                LinkedListNode <SnakePart> nextNode = currentNode.Next;
                if (nextNode != null)
                {
                    Tile tile = mm.GetTileInFrontOfSnakePart(currentNode.Value);
                    mm.PlaceItemOnTile(tile, nextNode.Value);
                }
                currentNode = nextNode;
            }
        }