コード例 #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);
 }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #5
0
ファイル: Blocks.cs プロジェクト: SirJosh3917/SwitchAsm
 public Portal(RelativePoint pos, BlockType id, PortalDirection rotation, int curId, int targetId) : this(pos, id, new PortalInfo(curId, targetId, rotation))
 {
 }
コード例 #6
0
ファイル: Blocks.cs プロジェクト: SirJosh3917/SwitchAsm
 public Switch(RelativePoint pos, BlockType id, int switchId)
 {
     this.Position = pos;
     this.Id       = id;
     this.SwitchId = switchId;
 }
コード例 #7
0
ファイル: Blocks.cs プロジェクト: SirJosh3917/SwitchAsm
 public IBlock Clone(RelativePoint newPos)
 => new Switch(this.Position.AddTo(newPos), this.Id, this.SwitchId);
コード例 #8
0
ファイル: Blocks.cs プロジェクト: SirJosh3917/SwitchAsm
 public IBlock Clone(RelativePoint newPos)
 => new Regular(this.Position.AddTo(newPos), this.Id);
コード例 #9
0
ファイル: Blocks.cs プロジェクト: SirJosh3917/SwitchAsm
 public Regular(RelativePoint pos, BlockType id)
 {
     this.Position = pos;
     this.Id       = id;
 }
コード例 #10
0
ファイル: Blocks.cs プロジェクト: SirJosh3917/SwitchAsm
 public RelativePoint AddTo(RelativePoint other)
 => new RelativePoint(other.X + this.X, other.Y + this.Y);
コード例 #11
0
ファイル: Blocks.cs プロジェクト: SirJosh3917/SwitchAsm
 public IBlock Clone(RelativePoint newPos)
 => new Portal(this.Position.AddTo(newPos), this.Id, this.PortalInfo);
コード例 #12
0
ファイル: Blocks.cs プロジェクト: SirJosh3917/SwitchAsm
 public Portal(RelativePoint pos, BlockType id, PortalInfo portalInfo)
 {
     this.Position   = pos;
     this.Id         = id;
     this.PortalInfo = portalInfo;
 }