示例#1
0
        public void SendBlock(IBlock Block)
        {
            switch (Block.Type)
            {
            case BlockType.SimpleBlock:
                SimpleBlock sb = Block as SimpleBlock;
                Send(WorldMap.Key, 0, Block.Position.X, Block.Position.Y, Block.ID);
                break;

            case BlockType.BackgroundBlock:
                BackgroundBlock bb = Block as BackgroundBlock;
                Send(WorldMap.Key, 1, Block.Position.X, Block.Position.Y, Block.ID);
                break;

            case BlockType.RotatableBlock:
                RotatableBlock rb = Block as RotatableBlock;
                Send(WorldMap.Key, 0, Block.Position.X, Block.Position.Y, Block.ID, (int)rb.Rotation);
                break;

            case BlockType.ValuedBlock:
                ValuedBlock vb = Block as ValuedBlock;
                Send(WorldMap.Key, 0, Block.Position.X, Block.Position.Y, Block.ID, vb.Value);
                break;

            case BlockType.PortalBlock:
                PortalBlock pb = Block as PortalBlock;
                Send(WorldMap.Key, 0, Block.Position.X, Block.Position.Y, Block.ID, (int)pb.Rotation, pb.Identificator, pb.Target);
                break;
            }
        }
 public ReadOnlyWorldDictionaryItem(BackgroundBlock background, int x, int y)
 {
     this._foreground = null;
     this._background = background;
     this.X           = x;
     this.Y           = y;
 }
示例#3
0
 public void Update(Point point, BackgroundBlock oldBlock, BackgroundBlock newBlock)
 {
     if (!this.TryUpdate(point, oldBlock, newBlock))
     {
         throw new InvalidOperationException("Unable to find the given oldBlock at the given location.");
     }
 }
示例#4
0
        public bool TryUpdate(Point point, BackgroundBlock oldBlock, BackgroundBlock newBlock)
        {
            if (!this.InternalBackground.Remove(oldBlock, point))
            {
                return(false);
            }

            this.InternalBackground.Add(newBlock, point);
            return(true);
        }
示例#5
0
 //Loads all the sprites once Unity is ready
 private void LoadSprites()
 {
     Dirt.LoadSprites();
     Ladder.LoadSprites();
     Bridge.LoadSprites();
     Trench.LoadSprites();
     Roof.LoadSprites();
     Platform.LoadSprites();
     BackgroundBlock.LoadSprites();
     Box.LoadSprites();
 }
示例#6
0
        public override bool Equals(System.Object Obj)
        {
            if (Obj == null)
            {
                return(false);
            }

            BackgroundBlock Block = Obj as BackgroundBlock;

            if ((System.Object)Block == null)
            {
                return(false);
            }

            return(this == Block);
        }
示例#7
0
        public void A_New_BackgroundBlock_Has_Background_Heading_On_First_Line()
        {
            var expectedString = "BHF: Hello, World";
            var mockStyle      = new MockStylist
            {
                BackgroundHeadingFormat = "BHF: {0}"
            };
            var scenario = new Scenario
            {
                Name = "Hello, World"
            };

            var backgroundBlock = new BackgroundBlock(scenario, mockStyle);
            var actualString    = backgroundBlock.ToString().Split(new string[] { Environment.NewLine }, StringSplitOptions.None);

            Assert.AreEqual(expectedString, actualString[0]);
            Assert.AreEqual(2, actualString.Length);
        }
示例#8
0
 public bool IsSameAs(IBlock Block)
 {
     if (this.Type == Block.Type)
     {
         BackgroundBlock BBlock = Block as BackgroundBlock;
         if (BBlock == this)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     else
     {
         return(false);
     }
 }
示例#9
0
        public static Block[,] GenerateGrid(Grid grid, Core data)
        {
            Erase(grid);
            grid.ColumnDefinitions.Add(GenerateLeftRightColumn());
            for (var i = 0; i < data.Width; i++)
            {
                grid.ColumnDefinitions.Add(GenerateColumn());
            }
            grid.ColumnDefinitions.Add(GenerateLeftRightColumn());
            grid.RowDefinitions.Add(GenerateTopBottomRow());
            for (var j = 0; j < data.Height; j++)
            {
                grid.RowDefinitions.Add(GenerateRow());
            }
            grid.RowDefinitions.Add(GenerateTopBottomRow());
            var answer    = new Block[data.Width, data.Height];
            var temp_list = new List <Block>();

            for (var i = 0; i < data.Width; i++)
            {
                for (var j = 0; j < data.Height; j++)
                {
                    var block = GenerateBlock(data[i, j]);
                    block.SetValue(Grid.RowProperty, j + 1);
                    block.SetValue(Grid.ColumnProperty, i + 1);
                    var back = new BackgroundBlock(block)
                    {
                        Margin = new Thickness(margin_value)
                    };
                    back.SetValue(Grid.RowProperty, j + 1);
                    back.SetValue(Grid.ColumnProperty, i + 1);
                    grid.Children.Add(back);
                    temp_list.Add(block);
                    answer[i, j] = block;
                }
            }
            foreach (var block in temp_list)
            {
                grid.Children.Add(block);
            }
            return(answer);
        }
示例#10
0
 public IBlockQuery <BackgroundBlock, BlocksItem> this[BackgroundBlock block] => this.Background[block];
示例#11
0
 public IBlockQuery <BackgroundBlock, ReadOnlyWorldDictionaryItem> this[BackgroundBlock block] => this.Background[block];
示例#12
0
 public bool EqualBackgroundBrickValues(BackgroundBlock b)
 {
     return(b.Type == this.Type);
 }
示例#13
0
 public DBBrick(BackgroundBlock b)
 {
     this.Type = b.Type;
 }
示例#14
0
        private void UnserializeFromComplexObject(DatabaseArray worlddata)
        {
            foreach (DatabaseObject ct in worlddata)
            {
                if (ct.Count == 0) continue;
                var type = (uint)ct.GetValue("type");
                var layerNum = ct.GetInt("layer", 0);
                var xs = ct.GetBytes("x", new byte[0]);
                var ys = ct.GetBytes("y", new byte[0]);

                if (layerNum == 0)
                {
                    var foreground = (Foreground.Id)type;
                    var block = WorldUtils.GetDatabaseBlock(ct, foreground);
                    for (var b = 0; b < xs.Length; b += 2)
                    {
                        var nx = (xs[b] << 8) + xs[b + 1];
                        var ny = (ys[b] << 8) + ys[b + 1];
                        this.Foreground[nx, ny] = block;
                    }
                }
                else
                {
                    var background = (Background.Id)type;
                    var block = new BackgroundBlock(background);
                    for (var b = 0; b < xs.Length; b += 2)
                    {
                        var nx = (xs[b] << 8) + xs[b + 1];
                        var ny = (ys[b] << 8) + ys[b + 1];
                        this.Background[nx, ny] = block;
                    }
                }
            }
        }
示例#15
0
 public void Set(BackgroundBlock block)
 {
     this._blocks.Place(this.X, this.Y, block);
 }
 public static bool TryUpdate <T>(this IWorldDictionary <T> worldDictionary, int x, int y, BackgroundBlock oldBlock, BackgroundBlock newBlock) where T : struct
 {
     return(worldDictionary.TryUpdate(new Point(x, y), oldBlock, newBlock));
 }
 public static void Update <T>(this IWorldDictionary <T> worldDictionary, int x, int y, BackgroundBlock oldBlock, BackgroundBlock newBlock) where T : struct
 {
     worldDictionary.Update(new Point(x, y), oldBlock, newBlock);
 }
示例#18
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;
        }
示例#19
0
 public TItem GenerateItem(Point point, BackgroundBlock block)
 {
     return(this._itemGenerator(point, block));
 }
示例#20
0
 public Background.Id GetId(BackgroundBlock block)
 {
     return(block.Id);
 }
示例#21
0
 public void Set(BackgroundBlock block)
 {
     this._blocks.Place(this._x, this._y, block);
 }