Exemplo n.º 1
0
        private bool CheckStartCell(Direction dir, CVector2 pos)
        {
            switch (dir)
            {
            case Direction.Top:
            {
                return(pos.Y - 2 > 0 && m[pos.X, pos.Y - 1] == 0 && m[pos.X, pos.Y - 2] == 0);
            }

            case Direction.Left:
            {
                return(pos.X - 2 > 0 && m[pos.X - 1, pos.Y] == 0 && m[pos.X - 2, pos.Y] == 0);
            }

            case Direction.Right:
            {
                return(pos.X + 1 < mSize && m[pos.X + 1, pos.Y] == 0 && m[pos.X + 2, pos.Y] == 0);
            }

            case Direction.Bottom:
            {
                return(pos.Y + 1 < mSize && m[pos.X, pos.Y + 1] == 0 && m[pos.X, pos.Y + 2] == 0);
            }
            }
            return(false);
        }
Exemplo n.º 2
0
        private Direction CheckAvailableCells(CVector2 pos)
        {
            Direction preferedDir = (Direction)randyTheRandomNumber.Next(4);

            if (CheckStartCell(preferedDir, pos))
            {
                return(preferedDir);
            }
            else if (CheckStartCell(preferedDir + 1, pos))
            {
                return(preferedDir + 1);
            }
            else if (CheckStartCell(preferedDir - 1, pos))
            {
                return(preferedDir - 1);
            }
            else if (CheckStartCell(preferedDir + 2, pos))
            {
                return(preferedDir + 2);
            }
            else
            {
                throw new Exception();
            }
        }
Exemplo n.º 3
0
        private CVector2 buildCorridor(CVector2 pos, Direction direction)
        {
            int lenght = randyTheRandomNumber.Next(maxCoridorLength) + 1;



            return(pos);
        }
Exemplo n.º 4
0
        public int[,] CreatePath()
        {
            remainingCells = mSize * mSize - 1;
            m[0, 0]        = 1;

            CVector2 currentPos = new CVector2(0, 0);

            while (remainingCells > acceptableWallCount)
            {
                currentPos = buildBlock(currentPos);
            }
            return(m);
        }
Exemplo n.º 5
0
        private CVector2 buildBlock(CVector2 pos)
        {
            try
            {
                Direction dir = CheckAvailableCells(pos);

                if (lastBlockIsRoom)
                {
                    buildCorridor(pos, dir);
                }
                else
                {
                    int cellDiff = corridorCells - roomCells;
                    if (cellDiff > ratioAcceptableDeviation)
                    {
                        buildRoom(pos, dir);
                    }
                    else if (cellDiff < -ratioAcceptableDeviation)
                    {
                        buildCorridor(pos, dir);
                    }
                    else if (randyTheRandomNumber.Next(2) == 0)
                    {
                        buildCorridor(pos, dir);
                    }
                    else
                    {
                        buildRoom(pos, dir);
                    }
                }
            }
            catch
            {
                //Force EXIT - Temporary
                remainingCells = 0;
            }


            return(pos);
        }
Exemplo n.º 6
0
        private CVector2 buildRoom(CVector2 pos, Direction direction)
        {
            int size = randyTheRandomNumber.Next(maxRoomSize - 3) + 4;

            return(pos);
        }