AStarXNA.Game1.Initialize C# (CSharp) Метод

Initialize() защищенный Метод

Allows the game to perform any initialization it needs to before starting to run. This is where it can query for any required services and load any non-graphic related content. Calling base.Initialize will enumerate through any components and initialize them as well.
protected Initialize ( ) : void
Результат void
        protected override void Initialize()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);
            Services.AddService(typeof(SpriteBatch), spriteBatch);
            grid = new Grid(this, 20) {DrawGridLines = true};
            cursor = new MouseCursor(this, spriteBatch, Content.Load<Texture2D>("cursor"));
            cursor.LeftClick += (o, e) => HandleLeftButton(e.Position);
            cursor.LeftDrag += (o, e) => HandleLeftButton(e.Position);
            cursor.RightClick += (o, e) => HandleRightButton(e.Position);
            cursor.RightDrag += (o, e) => HandleRightButton(e.Position);
            aStar = new AStar(this, grid, new ManhattanDistance());
            aStar.PathFound += (o, e) => {
                console.WriteLine(String.Format("Heuristic: {0}; Path length: {1}; Total Explored length: {2}", aStar.Heuristic.Name, e.TotalPathLength, e.TotalExplored));
                                             foreach (var cell in e.Path)
                                             {
                                                 cell.Type = GridCellType.Path;
                                             }
            };
            Components.Add(cursor);
            gameObjects.Add(grid);
            gameObjects.Add(aStar);

            var singleStroke = new SingleKeyStroke(this);
            singleStroke.KeyDown += (o, e) =>
                                        {
                                            if (console.Opened)
                                            {
                                                return;
                                            }
                                            if (e.Key == Keys.Space)
                                            {
                                                grid.DrawGridLines = !grid.DrawGridLines;
                                            }
                                            if (e.Key == Keys.Enter)
                                            {
                                                grid.Reset();
                                                aStar.Start();
                                            }
                                        };
            Components.Add(singleStroke);
            console = new GameConsole(this, spriteBatch, new IConsoleCommand[]
                                                             {
                                                                new DisplayGridlinesCommand(grid),
                                                                new ResetGridCommand(grid),
                                                                new CellSizeCommand(grid),
                                                                new SetHeuristicCommand(aStar),
                                                                new FullScreenCommand(graphics)
                                                             }, new GameConsoleOptions{Prompt=">", FontColor = Color.GreenYellow});

            base.Initialize();
        }