Ejemplo n.º 1
0
        protected override void Initialize()
        {
            var map = new Map(this, _isHard) {Location = new Vector2(10, 10)};
            map.Snake.CountBlockChanged += SnakeOnCountBlockChanged;
            Components.Add(map);

            var grid = new Grid(this, new Rectangle(graphics.PreferredBackBufferWidth - 150, 10, 140, graphics.PreferredBackBufferHeight - 30), new Vector2(140, graphics.PreferredBackBufferHeight - 30));
            grid.Color = Color.BlueViolet;
            Components.Add(grid);

            var statisticAppleBlock = new AppleBlock(this)
            {
                Location = new Vector2(graphics.PreferredBackBufferWidth - 140, 60),
                Size = new Vector2(30, 30)
            };
            Components.Add(statisticAppleBlock);

            _locationCountEatenApples = new Vector2(graphics.PreferredBackBufferWidth - 100, 50);

            base.Initialize();
        }
Ejemplo n.º 2
0
        public override void Initialize()
        {
            base.Initialize();

            // создание объектов карты
            // загрузка карты, первая строка - число с количеством блоков в строке
            var sr = new StreamReader(_path);
            SizeX = Int32.Parse(sr.ReadLine());
            var mask = sr.ReadToEnd().Replace("\r\n", string.Empty);

            _mask = new int[mask.Length / SizeX, SizeX];

            int dx = 0;
            int dy = 0;

            foreach (char item in mask)
            {
                if (dx == SizeX)
                {
                    dx = 0;
                    dy++;
                }

                if (item != '0')
                {
                    var wall = new Wall(Game) {Size = new Vector2(Helper.SizeBlock, Helper.SizeBlock), Location = new Vector2(startX + dx*Helper.SizeBlock, startY + dy*Helper.SizeBlock)};
                    Game.Components.Add(wall);
                    _mask[dy, dx] = Helper.MaskWallBlock;
                }
                else
                    _mask[dy, dx] = Helper.MaskEmptyBlock;

                dx++;
            }
            SizeY = dy;

            // insert snake
            int startIndexX = 6;
            int startIndexY = 2;
            _snake.Location = new Vector2(startX + startIndexX*Helper.SizeBlock, startY + startIndexY*Helper.SizeBlock);
            _snake.Vector = new Vector2(1, 0);
            Game.Components.Add(_snake);

            // добавляем яблоко
            _apple = new AppleBlock(Game);
            Game.Components.Add(_apple);
            AppleAdd();

            if (_withMangoose)
                MongooseAdd();
        }