示例#1
0
        internal static BlockDataWorld GetClearedWorld(int width, int height, Foreground.Id borderBlock)
        {
            var world = new BlockDataWorld(width, height);

            WorldUtils.DrawBorder(world, new BlockData <ForegroundBlock>(new ForegroundBlock(borderBlock)));
            return(world);
        }
示例#2
0
        private static BlockDataWorld GetWorld(Message m, int width, int height)
        {
            var world = new BlockDataWorld(width, height);
            var datas = InitParse.Parse(m);

            foreach (var data in datas)
            {
                var block = data.Type;
                var l     = (Layer)data.Layer;

                switch (l)
                {
                case Layer.Background:
                    var bgWorldBlock = new BackgroundBlock((Background.Id)block);
                    var bg           = new BlockData <BackgroundBlock>(bgWorldBlock);
                    foreach (var pos in data.Locations)
                    {
                        world.Background[pos.X, pos.Y] = bg;
                    }
                    break;

                case Layer.Foreground:
                    var fgWorldBlock = WorldUtils.GetForegroundFromArgs((Foreground.Id)block, data.Args);
                    var fg           = new BlockData <ForegroundBlock>(fgWorldBlock);
                    foreach (var pos in data.Locations)
                    {
                        world.Foreground[pos.X, pos.Y] = fg;
                    }
                    break;
                }
            }

            return(world);
        }
示例#3
0
 public ReadOnlyBlocksWorld(BlockDataWorld world)
 {
     this.Height     = world.Height;
     this.Width      = world.Width;
     this.Foreground = new ReadOnlyBlocksBlockLayer <BlockData <ForegroundBlock> >(world.Foreground);
     this.Background = new ReadOnlyBlocksBlockLayer <BlockData <BackgroundBlock> >(world.Background);
 }
示例#4
0
        internal static BlockDataWorld GetWorld(Message m, int width, int height, uint offset = InitOffset)
        {
            var  world   = new BlockDataWorld(width, height);
            uint pointer = GetStart(m, offset);

            string strValue2;

            while ((strValue2 = m[pointer] as string) == null || strValue2 != "we")
            {
                var    block      = m.GetInteger(pointer++);
                var    l          = (Layer)m.GetInteger(pointer++);
                byte[] byteArrayX = m.GetByteArray(pointer++);
                byte[] byteArrayY = m.GetByteArray(pointer++);

                switch (l)
                {
                case Layer.Background:
                    var bgWorldBlock = new BackgroundBlock((Background.Id)block);
                    foreach (Point pos in GetPos(byteArrayX, byteArrayY))
                    {
                        world.Background[pos.X, pos.Y] = new BlockData <BackgroundBlock>(bgWorldBlock);
                    }
                    break;

                case Layer.Foreground:
                    ForegroundBlock foregroundBlock;
                    BlockArgsType   blockArgsType = WorldUtils.GetBlockArgsType(WorldUtils.GetForegroundType(id: (Foreground.Id)block));

                    switch (blockArgsType)
                    {
                    case BlockArgsType.None:
                        foregroundBlock = new ForegroundBlock((Foreground.Id)block);
                        break;

                    case BlockArgsType.Number:
                        uint i = m.GetUInt(pointer++);
                        foregroundBlock = new ForegroundBlock((Foreground.Id)block, i);
                        break;

                    case BlockArgsType.String:
                        string str = m.GetString(pointer++);
                        foregroundBlock = new ForegroundBlock((Foreground.Id)block, str);
                        break;

                    case BlockArgsType.Portal:
                        var  portalRotation = (Morph.Id)m.GetUInt(pointer++);
                        uint portalId       = m.GetUInt(pointer++);
                        uint portalTarget   = m.GetUInt(pointer++);
                        foregroundBlock = new ForegroundBlock((Foreground.Id)block, portalId, portalTarget, portalRotation);
                        break;

                    case BlockArgsType.Label:
                        string text      = m.GetString(pointer++);
                        string textcolor = m.GetString(pointer++);
                        foregroundBlock = new ForegroundBlock((Foreground.Id)block, text, textcolor);
                        break;

                    default:
                        throw new NotSupportedException("Invalid block.");
                    }

                    var fg = new BlockData <ForegroundBlock>(foregroundBlock);
                    foreach (Point pos in GetPos(byteArrayX, byteArrayY))
                    {
                        world.Foreground[pos.X, pos.Y] = fg;
                    }
                    break;
                }
            }

            return(world);
        }
示例#5
0
 private void On(ClearEvent e)
 {
     this.World = GetClearedWorld(e.RoomWidth, e.RoomHeight, e.BorderBlock);
     new WorldResizeEvent(e.RoomWidth, e.RoomHeight)
     .RaiseIn(this.BotBits);
 }
示例#6
0
 private void On(LoadLevelEvent e)
 {
     this.World = GetWorld(e.PlayerIOMessage, this.Width, this.Height);
 }
示例#7
0
 private void On(InitEvent e)
 {
     this.World = GetWorld(e.PlayerIOMessage, e.WorldWidth, e.WorldHeight);
 }