예제 #1
0
        private Point getRandomPointOnTheSquareRadiusFor(Room outer_Room,Room inner_Room)
        {
            Point ret = null;

            Point start = inner_Room.ActualLocation;

            int lSqOuter = outer_Room.getMaxWidth();
            if ( outer_Room.getMaxLength() > lSqOuter ) lSqOuter = outer_Room.getMaxLength();
            int lSqInner = inner_Room.getMaxWidth();
            if ( inner_Room.getMaxLength() > lSqInner ) lSqInner = inner_Room.getMaxLength();

            int radius = (lSqInner+2)+(lSqOuter+2)+4;
            //start = new Point (start.x +inner_Room.getMaxWidth ()+1, start.y + inner_Room.getMaxWidth ()+1);
            start = new Point (start.x-lSqOuter-4, start.y-lSqOuter-4);

            //UnityEngine.Debug.Log("Start: "+start.x+","+start.y);

            int randomPoint = rng.Next (radius * 4);

            int rLine = randomPoint / radius;
            int rPos = randomPoint % radius;

            switch (rLine) {
            case 0:
                ret = new Point(start.x+rPos,start.y);
                break;

            case 1:
                ret = new Point(start.x+radius,start.y+rPos);
                break;

            case 2:
                ret = new Point(start.x+radius-rPos,start.y+radius);
                break;

            case 3:
                ret = new Point(start.x,start.y+radius-rPos);
                break;

            default:
                // WTF How did i get here?
                ret = new Point(-1,-1);
                break;
            }

            return ret;
        }
예제 #2
0
        private void buildHallway(Room r1, Room r2)
        {
            int mpX1, mpX2, mpY1, mpY2;
            bool stillInRoom, reEnteredRoom;

            // Find the mid points of both rectangles
            mpX1 = r1.ActualLocation.x + (r1.getMaxWidth () / 2 + 1);
            mpY1 = r1.ActualLocation.y + (r1.getMaxLength () / 2 + 1);
            mpX2 = r2.ActualLocation.x + (r2.getMaxWidth () / 2 + 1);
            mpY2 = r2.ActualLocation.y + (r2.getMaxLength () / 2 + 1);

            int cX, cY;
            bool emptyCheck = true;

            // Try Cross-point #1
            cX = mpX1;
            cY = mpY2;

            int delX = -1,delY = -1;
            int stX = mpX1,stY = mpY1;
            if ( cX > mpX1 || cX > mpX2 ) delX = 1;
            if ( cY > mpY1 || cY > mpY2 ) delY = 1;
            if ( cX == mpX1 ) stX = mpX2;
            if ( cY == mpY1 ) stY = mpY2;

            stillInRoom = true;
            reEnteredRoom = false;
            if ( delX == 1 ) {
                for ( int i = stX; i <= cX; i += delX ) {
                    if ( this[i,cY] == 99 ) {
                        if ( reEnteredRoom ) emptyCheck = false;
                        stillInRoom = false;
                    }
                    else {
                        if ( !stillInRoom ) { reEnteredRoom = true; }
                    }
                    //UnityEngine.Debug.Log ("["+i+","+cY+"]  ->   sIR: "+stillInRoom+"    eC: "+emptyCheck);
                }
            }
            else {
                for ( int i = stX; i >= cX; i += delX ) {
                    if ( this[i,cY] == 99 ) {
                        if ( reEnteredRoom ) emptyCheck = false;
                        stillInRoom = false;
                    }
                    else {
                        if ( !stillInRoom ) { reEnteredRoom = true; }
                    }
                    //UnityEngine.Debug.Log ("["+i+","+cY+"]  ->   sIR: "+stillInRoom+"    eC: "+emptyCheck);
                }
            }

            stillInRoom = true;
            reEnteredRoom = false;
            if ( delY == 1 ) {
                for ( int i = stY; i <= cY; i += delY ) {
                    if ( this[cX,i] == 99 ) {
                        if ( reEnteredRoom ) emptyCheck = false;
                        stillInRoom = false;
                    }
                    else {
                        if ( !stillInRoom ) { reEnteredRoom = true; }
                    }
                    //UnityEngine.Debug.Log ("["+cX+","+i+"]  ->   sIR: "+stillInRoom+"    eC: "+emptyCheck);
                }
            }
            else {
                for ( int i = stY; i >= cY; i += delY ) {
                    if ( this[cX,i] == 99 ) {
                        if ( reEnteredRoom ) emptyCheck = false;
                        stillInRoom = false;
                    }
                    else {
                        if ( !stillInRoom ) { reEnteredRoom = true; }
                    }
                    //UnityEngine.Debug.Log ("["+cX+","+i+"]  ->   sIR: "+stillInRoom+"    eC: "+emptyCheck);
                }
            }
            //emptyCheck = false;
            if ( emptyCheck ) {
                //UnityEngine.Debug.Log("EC1 -- > stX: "+stX+"   stY: "+stY+"   delX: "+delX+"   cX: "+cX+"   cY: "+cY+"   delY: "+delY);
                // This path is clear, so build it!
                if ( delX == 1 ) { for ( int i = stX; i <= cX; i += delX ) if ( this[i,cY] >= 98 ) placeHallAt(i,cY); }
                else {			   for ( int i = stX; i >= cX; i += delX ) if ( this[i,cY] >= 98 ) placeHallAt(i,cY); }
                if ( delY == 1 ) { for ( int i = stY; i <= cY; i += delY ) if ( this[cX,i] >= 98 ) placeHallAt(cX,i); }
                else { 			   for ( int i = stY; i >= cY; i += delY ) if ( this[cX,i] >= 98 ) placeHallAt(cX,i); }
            }
            else {
                // Try Cross-point #2
                cX = mpX2;
                cY = mpY1;

                delX = -1; delY = -1;
                stX = mpX1; stY = mpY1;
                if ( cX > mpX1 || cX > mpX2 ) delX = 1;
                if ( cY > mpY1 || cY > mpY2 ) delY = 1;
                if ( cX == mpX1 ) stX = mpX2;
                if ( cY == mpY1 ) stY = mpY2;

                emptyCheck = true;

                stillInRoom = true;
                reEnteredRoom = false;
                if ( delX == 1 ) {
                    for ( int i = stX; i <= cX; i += delX ) {
                        if ( this[i,cY] == 99 ) {
                            if ( reEnteredRoom ) emptyCheck = false;
                            stillInRoom = false;
                        }
                        else {
                            if ( !stillInRoom ) { reEnteredRoom = true; }
                        }
                        UnityEngine.Debug.Log ("["+i+","+cY+"]  ->   sIR: "+stillInRoom+"    eC: "+emptyCheck);
                    }
                }
                else {
                    for ( int i = stX; i >= cX; i += delX ) {
                        if ( this[i,cY] == 99 ) {
                            if ( reEnteredRoom ) emptyCheck = false;
                            stillInRoom = false;
                        }
                        else {
                            if ( !stillInRoom ) { reEnteredRoom = true; }
                        }
                        UnityEngine.Debug.Log ("["+i+","+cY+"]  ->   sIR: "+stillInRoom+"    eC: "+emptyCheck);
                    }
                }

                stillInRoom = true;
                reEnteredRoom = false;
                if ( delY == 1 ) {
                    for ( int i = stY; i <= cY; i += delY ) {
                        if ( this[cX,i] == 99 ) {
                            if ( reEnteredRoom ) emptyCheck = false;
                            stillInRoom = false;
                        }
                        else {
                            if ( !stillInRoom ) { reEnteredRoom = true; }
                        }
                        UnityEngine.Debug.Log ("["+cX+","+i+"]  ->   sIR: "+stillInRoom+"    eC: "+emptyCheck);
                    }
                }
                else {
                    for ( int i = stY; i >= cY; i += delY ) {
                        if ( this[cX,i] == 99 ) {
                            if ( reEnteredRoom ) emptyCheck = false;
                            stillInRoom = false;
                        }
                        else {
                            if ( !stillInRoom ) { reEnteredRoom = true; }
                        }
                        UnityEngine.Debug.Log ("["+cX+","+i+"]  ->   sIR: "+stillInRoom+"    eC: "+emptyCheck);
                    }
                }

                if ( emptyCheck ) {
                    //UnityEngine.Debug.Log("EC2 -- > stX: "+stX+"   stY: "+stY+"   delX: "+delX+"   cX: "+cX+"   cY: "+cY+"   delY: "+delY);
                    // This path is clear, so build it!
                    if ( delX == 1 ) { for ( int i = stX; i <= cX; i += delX ) if ( this[i,cY] >= 98 ) placeHallAt(i,cY); }
                    else {			   for ( int i = stX; i >= cX; i += delX ) if ( this[i,cY] >= 98 ) placeHallAt(i,cY); }
                    if ( delY == 1 ) { for ( int i = stY; i <= cY; i += delY ) if ( this[cX,i] >= 98 ) placeHallAt(cX,i); }
                    else { 			   for ( int i = stY; i >= cY; i += delY ) if ( this[cX,i] >= 98 ) placeHallAt(cX,i); }
                }
                else {
                    UnityEngine.Debug.Log("Err -- >"+
                                          "   mp1: ["+mpX1+","+mpY1+"]"+
                                          "   mp2: ["+mpX2+","+mpY2+"]"
                                        );
                    UnityEngine.Debug.Log("Unable to draw a hallway!!");
                }

            } // End Else -> Cross-Point #2
        }