Exemple #1
0
        public GameForm()
        {
            try {
                this.KeyPreview = true;
                InfoLog.WriteInfo("MainForm constructor starts", EPrefix.Menu);

                InitializeComponent();

                /* Play peaceful music */
                AudioEngine.Instance.Music.PlayNext(MusicType.Peace);

                this.gameFormClose = false;
                this.FormClosing  += new FormClosingEventHandler(MainForm_FormClosing);

                Connection.Instance.ConnectionLost += new ConnectionLostEventHandler(ConnectionInstance_ConnectionLost);

                _gameLogic = new GameLogic();
                _gameLogic.Simulation.BuildingCompleted += new ClientSimulation.BuildingCreationHandler(Simulation_OnBuildingCompleted);
                _gameLogic.Simulation.UnitCompleted     += new ClientSimulation.UnitHandler(Simulation_OnUnitCompleted);
                //_gameLogic.Simulation.onTurnEnd += new SimulationHandler(Simulation_onTurnEnd);
                _gameLogic.Simulation.OnCreditsUpdate += new ClientSimulation.OnCreditsHandler(UpdateCredits);

                //_gameLogic.Simulation.onTurnEnd += new SimulationHandler(_buildManager.ProcessTurn);
                _gameLogic.Simulation.BuildingDestroyed += new ClientSimulation.BuildingHandler(Simulation_BuildingDestroyed);
                _gameLogic.Simulation.UpdateStripItem   += new ClientSimulation.UpdateStripItemHandler(this.UpdateStrip);
                _gameLogic.GameEnd     += new GameLogic.GameEndHandler(Simulation_GameEnd);
                _gameLogic.PauseResume += new GameLogic.PauseResumeHandler(this.onPauseResume);

                leftStripe.onBuildingChosen  += new BuildingChosenHandler(leftStripe_onBuildingChosen);
                rightStripe.onBuildingChosen += new BuildingChosenHandler(rightStripe_onBuildingChosen);
                rightStripe.onUnitChosen     += new UnitChosenHandler(rightStripe_onUnitChosen);
                _buildManager = new BuildManager(this._gameLogic, this.leftStripe, this.rightStripe);
                //_buildManager.CreateUnit += new CreateUnitHandler(this.PlaceUnit);
                _gameLogic.Simulation.InvalidBuild += new ClientSimulation.InvalidBuildHandler(_buildManager.OnBadLocation);
                _gameLogic.OnBadLocation           += new GameLogic.BadLocationHandler(_buildManager.OnBadLocation);


                InfoLog.WriteInfo("MainForm constructor: initializing OpenGL", EPrefix.GameGraphics);

                //initializes GameGraphics
                this.miniMap.InitializeContexts();
                this.mapView.InitializeContexts();
                mapView.MakeCurrent();

                //First: set appropriate properties
                InfoLog.WriteInfo("MainForm constructor: initializing GameLogic", EPrefix.GameGraphics);
                GameGraphics.InitGL(_gameLogic, this, mapView, miniMap);
                GameGraphics.SetViewSize(mapView.Width, mapView.Height);
                InfoLog.WriteInfo("MainForm constructor: initializing Textures", EPrefix.GameGraphics);
                GameGraphics.InitTextures(_gameLogic.Simulation);

                InfoLog.WriteInfo("MainForm constructor: initializing OpenGL finished", EPrefix.GameGraphics);

                //GameGraphics.GameGraphicsChanged += new EventHandler(gg_GameGraphicsChanged);

                this.MouseWheel += new MouseEventHandler(MainForm_MouseWheel);

                GameMessageHandler.Instance.GameInitialization += new GameInitEventHandler(Instance_GameInitialization);

                GameMessageHandler.Instance.Resume();
            } catch (Exception e) {
                Console.Out.WriteLine(e);
                MessageBox.Show(e.ToString());
            }
        }