Exemplo n.º 1
0
    public ImageContainer PopImageContainers(int n)
    {
        ImageContainer t          = top;
        ImageContainer popStart   = null;
        ImageContainer lastPopped = null;
        int            i          = 0;

        while (t != null && i++ < n)
        {
            if (lastPopped == null)
            {
                popStart = t;
            }
            lastPopped = t;
            //they are already linked so ne need to link them again
            //just move the top down
            top = top.getNext();
            //reduce the total perimeter in the image bank
            this.perimeter -= t.getWidth();
            this.totalContainers--;
            t = t.getNext();
        }
        if (lastPopped != null)
        {
            lastPopped.setNext(null);            //to terminate the list
        }
        return(popStart);
    }
Exemplo n.º 2
0
    public void ComputeRoomDimensionsBasisImageList(ImageBank imageBank, double unitWidth)
    {
        //Compute the total perimeter needed
        ImageContainer t = imageList;
        double         totalPerimeterNeeded       = 0;
        double         largestImageContainerWidth = 0;

        while (t != null)
        {
            totalPerimeterNeeded += t.getWidth();
            if (t.getWidth() > largestImageContainerWidth)
            {
                largestImageContainerWidth = t.getWidth();
            }
            t = t.getNext();
        }


        // 3 units will be reserved for the opening
        if (largestImageContainerWidth < 3 * unitWidth)
        {
            largestImageContainerWidth = 3 * unitWidth;
        }
        int p = Units(totalPerimeterNeeded + 3 * unitWidth, unitWidth);
        int l = Units(largestImageContainerWidth, unitWidth);

        bool randomizeWidth = (Random.value > 0.5);
        int  min            = 6;
        int  max            = 12;

        if (randomizeWidth)
        {
            width  = Random.Range(l, LargestWidth + 1);
            height = (p - 2 * width) / 2 + Random.Range(min, max);
            if (height < min)
            {
                height = min;
            }
        }
        else
        {
            height = Random.Range(l, LargestWidth + 1);
            width  = (p - 2 * height) / 2 + Random.Range(min, max);
            if (width < min)
            {
                width = min;
            }
        }

        if (width < min || height < min)
        {
            Debug.Log("wrong dimension");
        }
    }