示例#1
0
        public Cell CalculateNewPotentialRoomInDirection(Cell lastAddedCell, Direction direction)
        {
            Point location = Point.Empty;
            int posX = 0;
            int posY = 0;

            switch (direction)
            {
                case Direction.North:

                    location = new Point(lastAddedCell.PictureBox.Location.X,
                                         lastAddedCell.PictureBox.Location.Y - lastAddedCell.PictureBox.Height);
                    posX = lastAddedCell.PosX;
                    posY = lastAddedCell.PosY - 1;

                    break;

                case Direction.East:
                    location = new Point(lastAddedCell.PictureBox.Location.X + lastAddedCell.PictureBox.Width,
                                       lastAddedCell.PictureBox.Location.Y);
                    posX = lastAddedCell.PosX + 1;
                    posY = lastAddedCell.PosY;
                    break;

                case Direction.South:
                    location = new Point(lastAddedCell.PictureBox.Location.X,
                                       lastAddedCell.PictureBox.Location.Y + lastAddedCell.PictureBox.Height);
                    posX = lastAddedCell.PosX;
                    posY = lastAddedCell.PosY + 1;
                    break;

                case Direction.West:
                    location = new Point(lastAddedCell.PictureBox.Location.X - lastAddedCell.PictureBox.Width,
                                      lastAddedCell.PictureBox.Location.Y);
                    posX = lastAddedCell.PosX - 1;
                    posY = lastAddedCell.PosY;
                    break;

                default:
                    break;
            }

            if (posX<0 || posX > _maxCellX )
            {
                return null;
            }

            if (posY < 1 || posY > _maxCellY)
            {
                return null;
            }

            var newCell = CreateNewCell(location, 0, Constants.RoomId, lastAddedCell.PictureBox.Width, lastAddedCell.PictureBox.Height, posX, posY );
            return newCell;
        }
示例#2
0
 void cell_CreateFromHere(Cell cell)
 {
     this.LastAddedCell = cell;
 }
示例#3
0
        public Cell TryAddNewRoomToExistingOne(Cell lastAddedCell, int minDistanceToNextRoom)
        {
            if (lastAddedCell == null)
            {
                //error
                throw new ArgumentNullException("lastAddedCell");
            }

            lastAddedCell.ReadAdjacentRooms(GetAllCells());

            if (lastAddedCell.RoomToAddAnymore == false)
            {
                return null;
            }

            while (lastAddedCell.RoomToAddAnymore)
            {
                Direction nextDirectionToCheck;
                //find next direction to try
                while (true)
                {
                    Direction direction = LstAllValidDirections[_rng.Next(0,4)];

                    if (lastAddedCell._lstAdjacentCells.Any(x => x.Direction == direction) == false)
                    {
                        nextDirectionToCheck = direction;
                        break;
                    }
                }

                //try to add new room
                Cell newPotentialCell = TryAddNewCellInDirection(lastAddedCell, nextDirectionToCheck);

                if (newPotentialCell == null)
                {
                    continue;
                }

                //add new direction
                lastAddedCell._lstAdjacentCells.Add(new DirectionCellContainer() { Direction = nextDirectionToCheck, Cell = newPotentialCell });

                if (newPotentialCell != null)
                {
                    return newPotentialCell;
                }
            }

            return null;
        }
示例#4
0
        public Cell TryAddNewCellInDirection(Cell lastAddedCell, Direction direction)
        {
            //create room
            Cell newPotentialCell = CalculateNewPotentialRoomInDirection(lastAddedCell, direction);

            if (newPotentialCell == null)
            {
                lastAddedCell._lstAdjacentCells.Add(new DirectionCellContainer() {Cell = null, Direction = direction});
                return null;
            }

            if (this.PictureBox.Bounds.Contains(newPotentialCell.PictureBox.Bounds) == false)
            {
                lastAddedCell._lstAdjacentCells.Add(new DirectionCellContainer() { Cell = null, Direction = direction });
                return null;
            }

            var foundCell = GetAllCells().FirstOrDefault(x => x.PictureBox.Bounds.Location == newPotentialCell.PictureBox.Bounds.Location);
            if (foundCell == null)
            {
                //check if collides
                this.AddNewEntity(newPotentialCell, _controlAll);
                return newPotentialCell;
            }
            else
            {

                return null;
            }
        }
示例#5
0
        public Cell CreateNewCell(Point point, int rotation, string id, int width, int height, int posX, int posY)
        {
            var cell = new Cell(point, rotation, id, width, height, posX, posY);

            cell.CreateFromHere += cell_CreateFromHere;

            return cell;
        }
示例#6
0
 public virtual void FireCreateFromHereEvent(Cell cell)
 {
     if (CreateFromHere != null)
     {
         CreateFromHere(cell);
     }
 }