Esempio n. 1
0
        void Simulation_GameEnd(int winTeamId)
        {
            InfoLog.WriteInfo("Game End Event", EPrefix.ClientInformation);

            //GameGraphics.GameGraphicsChanged -= new EventHandler(gg_GameGraphicsChanged);
            //mapView.Paint -= new PaintEventHandler(openGLView_Paint);

            GameGraphics.DeinitGL();

            _gameLogic.Simulation.AbortSimulation();

            _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.InvalidBuild    -= new ClientSimulation.InvalidBuildHandler(_buildManager.OnBadLocation);
            //_gameLogic.Simulation.onTurnEnd -= new SimulationHandler(_buildManager.ProcessTurn);
            _gameLogic.Simulation.BuildingDestroyed -= new ClientSimulation.BuildingHandler(Simulation_BuildingDestroyed);
            _gameLogic.Simulation.UpdateStripItem   -= new ClientSimulation.UpdateStripItemHandler(this.UpdateStrip);
            _gameLogic.OnBadLocation -= new GameLogic.BadLocationHandler(_buildManager.OnBadLocation);
            _gameLogic.GameEnd       -= new GameLogic.GameEndHandler(Simulation_GameEnd);
            _gameLogic.PauseResume   -= new GameLogic.PauseResumeHandler(this.onPauseResume);

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

            bool   isWinner           = false;
            string endGameInformation = string.Empty;

            if (winTeamId == _gameLogic.CurrentPlayer.TeamID)
            {
                isWinner = true;
            }

            /* Playing proper music */
            if (isWinner)
            {
                endGameInformation = "Congratulations, you won!";
                AudioEngine.Instance.Music.Play(MusicType.Win);
                AudioEngine.Instance.Sound.PlayHouse(_gameLogic.CurrentPlayer.House, HouseSoundType.Win);
            }
            else
            {
                endGameInformation = "Unfortunately you lost!";
                AudioEngine.Instance.Music.Play(MusicType.Lose);
                AudioEngine.Instance.Sound.PlayHouse(_gameLogic.CurrentPlayer.House, HouseSoundType.Lose);
            }

            /*
             * KŒ: tu jest burdel, GameForm nie jest od przepinania handlerów, ani od zarz¹dzania okienkami w aplikacji
             * nie mo¿na wyœwietliæ GameForm jako okna modalnego, albo zrobiæ w nim event?
             */

            /* Sending message to server */
            GameEndMessage gameEndMessage = (GameEndMessage)Utils.CreateMessageWithSenderId(MessageType.EndGame);

            gameEndMessage.HasWon = isWinner;

            /* Managing the UI */
            MainMenuForm mainMenuForm = FormPool.GetForm(Views.ChatForm) as MainMenuForm;

            if (mainMenuForm != null)
            {
                mainMenuForm.MenuMessageHandler.Suspend();
            }

            Connection.Instance.MessageHandler = mainMenuForm.MenuMessageHandler;
            Connection.Instance.SendMessage(gameEndMessage);
            this.OnMessageBoxShow(endGameInformation, "Game End", MessageBoxButtons.OK, MessageBoxIcon.Information);
            /* Stop playing music */
            AudioEngine.Instance.Music.Stop();

            this.GameFormClose = true;
            if (this.InvokeRequired)
            {
                this.Invoke(new MethodInvoker(this.Close));
            }
            else
            {
                this.Close();
            }

            // dosyc nieladne, bo to moze byc przejscie i z pause i z gamemenu (bo moga byc nad gameform)
            OnMenuOptionChange(new MenuOptionArg(MenuOption.Exit, this, true));

            if (mainMenuForm != null)
            {
                mainMenuForm.MenuMessageHandler.Resume();
            }

            //_gameLogic.Simulation.AbortSimulation();
        }