Пример #1
0
        public Brick(Point xy, int width, Level.BrickType brickType)
        {
            this.xy        = xy;
            this.width     = width;
            this.brickType = brickType;

            if (brickType == Level.BrickType.NORMAL)
            {
                this.brickColor = Color.Gold;
                lives           = 1;
            }
            else if (brickType == Level.BrickType.STONE)
            {
                this.brickColor = Color.LightGray;
                lives           = 2;
            }

            else if (brickType == Level.BrickType.DIAMOND)
            {
                this.brickColor = Color.CornflowerBlue;
                lives           = 3;
            }
        }
Пример #2
0
        public void generateMap()
        {
            string path = System.IO.Path.GetDirectoryName(Application.ExecutablePath);

            int    width          = startupConfig.width / 10;
            int    rows           = Level.maxHeight / Brick.height;
            int    numberOfBricks = startupConfig.width / width;
            Random rand           = new Random();

            for (int k = 0; k < 10; k++)
            {
                List <Brick> bricks = new List <Brick>();

                for (int i = 0; i < rows; i++)
                {
                    for (int j = 0; j < numberOfBricks; j++)
                    {
                        Level.BrickType brType = Level.BrickType.NORMAL;
                        int             random = 0;
                        if (startupConfig.num_levels < 2)
                        {
                            random = rand.Next(0, 1);
                        }
                        else if (startupConfig.num_levels >= 2 & startupConfig.num_levels < 5)
                        {
                            random = rand.Next(0, 2);
                        }
                        else if (startupConfig.num_levels >= 5)
                        {
                            random = rand.Next(0, 3);
                        }

                        if (random == 0)
                        {
                            brType = Level.BrickType.NORMAL;
                        }
                        else if (random == 1)
                        {
                            brType = Level.BrickType.STONE;
                        }
                        else if (random == 2)
                        {
                            brType = Level.BrickType.DIAMOND;
                        }

                        bricks.Add(new Brick(new Point(j * width, i * Brick.height + GameScreen.dynamicHeigth), width, brType));
                    }
                }

                startupConfig.num_levels++;
                string     FileName           = "..//..//..//levels/level_" + startupConfig.num_levels + ".bb";
                IFormatter serializeFormatter = new BinaryFormatter();

                using (FileStream fileStream = new FileStream(FileName, FileMode.Create))
                {
                    IFormatter formatter = new BinaryFormatter();
                    Level      tmplvl    = new Level(bricks, startupConfig);
                    tmplvl.id = k + 1;
                    formatter.Serialize(fileStream, tmplvl);
                }

                startupConfig.levels.Add(new Level(startupConfig.num_levels, FileName));
            }
            Config.serializeConfig(startupConfig, Config.confFilePath);
        }