Пример #1
0
        private static void BlockCommand(int key3, IBlock block)
        {
            ICommand cmd = null;

            switch (key3)
            {
            case 'C':
                cmd = new CoinItemCommand(block);
                break;

            case 'M':
                cmd = new SuperMushroomItemCommand(block);
                break;

            case 'F':
                cmd = new FireFlowerItemCommand(block);
                break;

            case 'O':
                cmd = new OneUpMushroomItemCommand(block);
                break;

            case 'S':
                cmd = new StarItemCommand(block);
                break;

            default:
                break;
            }
            if (cmd != null)
            {
                block.AddCommand(cmd);
            }
        }
Пример #2
0
        private static IBlock BuildBlock(int key2, int key3, int key4, int XPos, int YPos, QuadTree quad, string code, List <Button> buttons)
        {
            IBlock block = null;

            switch (key2)
            {
            case 'A':
                foreach (Button button in buttons)
                {
                    if (!button.Set)
                    {
                        block      = button;
                        button.Set = true;
                        break;
                    }
                }
                break;

            case 'B':
                block = BlockFactory.Instance.BrickBlock();
                if (code.Length == 4)
                {
                    int i = 0;
                    while (code[3] - '0' > i)
                    {
                        BlockCommand(key3, block);
                        i++;
                    }
                }
                else
                {
                    BlockCommand(key3, block);
                }
                break;

            case 'C':
                if (code.Length == 6)
                {
                    block = BlockFactory.Instance.DisappearingBlockSkin((char)key4, char.Parse(code.Substring(4, 1)), char.Parse(code.Substring(5, 1)));
                }
                else if (code.Length == 5)
                {
                    block = BlockFactory.Instance.DisappearingBlockSkin((char)key4, char.Parse(code.Substring(4, 1)));
                }
                else
                {
                    block = BlockFactory.Instance.DisappearingBlockSkin((char)key4);
                }
                buttons[key3 - '0'].RaisePressEvent += ((DisappearingBlock)block).HandleButtonPress;
                break;

            case 'F':
                switch (key3)
                {
                case 'U':
                    block = CreateUndergroundBlock(code[3]);
                    break;

                case 'C':
                    block = BlockFactory.Instance.CastleFloorBlock();
                    break;

                default:
                    block = BlockFactory.Instance.FloorBlock();
                    if (key3 == 'Z')
                    {
                        block.Collidable = false;
                    }
                    break;
                }
                break;

            case 'P':
                block = BuildPipeBlock(key3);
                break;

            case 'Q':
                QuestionBlock qb = BlockFactory.Instance.QuestionBlockQ();
                qb.Position = new Vector2(XPos, YPos);
                ICommand qcmd = null;
                //if key2 == Q, then there valid key3
                switch (key3)
                {
                case 'C':
                    qcmd = new CoinItemCommand(qb);
                    break;

                case 'M':
                    qcmd = new SuperMushroomItemCommand(qb);
                    break;

                case 'F':
                    qcmd = new FireFlowerItemCommand(qb);
                    break;

                case 'S':
                    qcmd = new StarItemCommand(qb);
                    break;

                case 'O':
                    qcmd = new OneUpMushroomItemCommand(qb);
                    break;

                case 'H':
                    block = BlockFactory.Instance.HiddenQuestionBlock();
                    BlockCommand(key3, block);
                    break;

                case 'U':
                    qb.Position = new Vector2(XPos, YPos);
                    qb.StraightToUsed();
                    break;

                default:
                    block = BlockFactory.Instance.QuestionBlock();
                    break;
                }
                if (qcmd != null)
                {
                    quad.Insert(qb);
                    qb.AddCommand(qcmd);
                }
                break;

            case 'R':
                block = BlockFactory.Instance.RockBlock();
                Point size = new Point()
                {
                    X = block.Texture.Width / 3,
                    Y = block.Texture.Height / 3
                };

                block.SourceRectangle = BlockPart(key3, key4, size);
                break;

            case 'T':
                block = BlockFactory.Instance.ToggleBlock();
                for (int i = 3; i < code.Length; i++)
                {
                    buttons[code[i] - '0'].RaisePressEvent += ((ToggleBlock)block).HandleButtonPress;
                }
                if (code[2] == 'H')
                {
                    block.SourceRectangle       = new Rectangle(new Point(0), new Point(block.Texture.Width, block.Texture.Height / 2));
                    block.Collidable            = false;
                    ((ToggleBlock)block).StartY = block.SourceRectangle.Y;
                }
                else
                {
                    block.SourceRectangle       = new Rectangle(new Point(0, block.Texture.Height / 2), new Point(block.Texture.Width, block.Texture.Height / 2));
                    ((ToggleBlock)block).StartY = 32;
                }
                break;

            case 'H':
                block = BlockFactory.Instance.HiddenBrickBlock();
                break;

            case 'W':
                switch (key3)
                {
                case 'U':
                    block = BlockFactory.Instance.WarpUpTop();
                    break;

                case 'L':
                    block = BlockFactory.Instance.WarpLeft();
                    break;

                case 'R':
                    block = BlockFactory.Instance.WarpRight();
                    break;
                }
                ((WarpEntranceBlock)block).Warp            = key4 - '0';
                ((WarpEntranceBlock)block).RaiseWarpEvent += Stage.HandleWarp;
                break;

            case 'I':
                EntityWarpBlock warpBlock = (EntityWarpBlock)BlockFactory.Instance.WarpEntityTop();
                ICommand        wCommand  = null;
                switch (key3)
                {
                case 'C':
                    wCommand = new CoinItemCommand(warpBlock);
                    break;

                case 'M':
                    wCommand = new SuperMushroomItemCommand(warpBlock);
                    break;

                case 'F':
                    wCommand = new FireFlowerItemCommand(warpBlock);
                    break;

                case 'S':
                    wCommand = new StarItemCommand(warpBlock);
                    break;

                case 'O':
                    wCommand = new OneUpMushroomItemCommand(warpBlock);
                    break;

                case 'G':
                    wCommand = new CreateEnemyCommand(AbstractEntity.EntityType.Goomba, warpBlock);
                    break;

                case 'K':
                    wCommand = new CreateEnemyCommand(AbstractEntity.EntityType.GreenKoopa, warpBlock);
                    break;

                case 'R':
                    wCommand = new CreateEnemyCommand(AbstractEntity.EntityType.RedKoop, warpBlock);
                    break;

                case 'P':
                    wCommand = new CreateEnemyCommand(AbstractEntity.EntityType.PiranhaPlant, warpBlock);
                    break;
                }
                warpBlock.Command  = wCommand;
                warpBlock.Position = new Vector2(XPos, YPos);
                Rectangle box = warpBlock.CollisionBox;
                box.X     -= box.Width / 2;
                box.Width *= 2;
                box.Y      = warpBlock.CollisionBox.Y - warpBlock.TrueHeight();
                box.Height = (int)(quad.Bounds.Height - YPos + warpBlock.CollisionBox.Height * 1.5);
                CollisionZone hz = new CollisionZone(box)
                {
                    LookingFor = AbstractEntity.EntityType.Mario
                };
                hz.RaiseEnterEvent += warpBlock.HandleEnterEvent;
                hz.RaiseLeaveEvent += warpBlock.HandleLeaveEvent;
                quad.Insert(warpBlock);
                quad.Insert(hz);
                break;

            case 'Y':
                block = BlockFactory.Instance.PyramidBlock();
                break;
            }
            return(block);
        }