Exemple #1
0
 public static bool BlockExistsAt(this IEnumerable <IBlock> blocks, RelativePoint point)
 {
     foreach (var i in blocks)
     {
         if (i.Position.X == point.X && i.Position.Y == point.Y)
         {
             return(true);
         }
     }
     return(false);
 }
Exemple #2
0
        public static bool FitsInRegion(this IEnumerable <IBlock> blocks, IEnumerable <IBlock> world, int x, int y)
        {
            var relPoint = new RelativePoint(x, y);

            foreach (var i in blocks)
            {
                if (world.BlockExistsAt(i.Position.AddTo(relPoint)))
                {
                    return(false);
                }
            }
            return(true);
        }
Exemple #3
0
        public static RelativePoint LowestBlock(this IEnumerable <IBlock> blocks)
        {
            var pos = new RelativePoint();

            foreach (var i in blocks)
            {
                if (i.Position.X > pos.X)
                {
                    pos = new RelativePoint(i.Position.X, pos.Y);
                }
                if (i.Position.Y > pos.Y)
                {
                    pos = new RelativePoint(pos.X, i.Position.Y);
                }
            }

            return(pos);
        }
Exemple #4
0
        public static IEnumerable <IBlock> BuildWorld(this IEnumerable <Module> mods, int maxX, int maxY)
        {
            var blocks = new List <IBlock>();

            foreach (var i in mods)
            {
                var blks = i.GetBlocks();

                var lowest = blks.LowestBlock();

                var regX = int.MaxValue;
                var regY = int.MaxValue;

                for (var x = 0; x < maxX - lowest.X; x++)
                {
                    for (var y = 0; y < maxY - lowest.Y; y++)
                    {
                        if (blks.FitsInRegion(blocks, x, y))
                        {
                            regX = x;
                            regY = y;

                            x = maxX;                             // break out of the loop
                            y = maxY;
                        }
                    }
                }

                var relPoint = new RelativePoint(regX, regY);

                foreach (var j in blks)
                {
                    blocks.Add(j.Clone(relPoint));
                }
            }

            return(blocks);
        }
Exemple #5
0
 public Portal(RelativePoint pos, BlockType id, PortalDirection rotation, int curId, int targetId) : this(pos, id, new PortalInfo(curId, targetId, rotation))
 {
 }
Exemple #6
0
 public Switch(RelativePoint pos, BlockType id, int switchId)
 {
     this.Position = pos;
     this.Id       = id;
     this.SwitchId = switchId;
 }
Exemple #7
0
 public IBlock Clone(RelativePoint newPos)
 => new Switch(this.Position.AddTo(newPos), this.Id, this.SwitchId);
Exemple #8
0
 public IBlock Clone(RelativePoint newPos)
 => new Regular(this.Position.AddTo(newPos), this.Id);
Exemple #9
0
 public Regular(RelativePoint pos, BlockType id)
 {
     this.Position = pos;
     this.Id       = id;
 }
Exemple #10
0
 public RelativePoint AddTo(RelativePoint other)
 => new RelativePoint(other.X + this.X, other.Y + this.Y);
Exemple #11
0
 public IBlock Clone(RelativePoint newPos)
 => new Portal(this.Position.AddTo(newPos), this.Id, this.PortalInfo);
Exemple #12
0
 public Portal(RelativePoint pos, BlockType id, PortalInfo portalInfo)
 {
     this.Position   = pos;
     this.Id         = id;
     this.PortalInfo = portalInfo;
 }