Пример #1
0
        public void RemoveScreenByName()
        {
            _screenManager.AddScreen(_screen);
            _screenManager.RemoveScreen(_screen.Name);

            _screenManager.Screens.ShouldNotContainKey(_screen.Name);
        }
Пример #2
0
        public override void Update(TimeSpan elapsed)
        {
            if (_screenManager.InputManager.State.KeyPressed == Key.Enter)
            {
                var screen = new GameScreen(_screenManager, _rendererWidth, _rendererHeight);
                _screenManager.AddScreen(screen);
                _screenManager.RemoveScreen(this);

                screen.Show();
            }
        }
Пример #3
0
        private void ReturnToMainMenu(object sender, EventArgs eventArgs)
        {
            mDirector.GetStoryManager.Level.GameScreen.Unload();
            mDirector.GetClock       = new Clock();
            mDirector.GetIdGenerator = new IdGenerator();
            mDirector.GetInputManager.RemoveEverythingFromInputManager();
            mDirector.GetStoryManager = new StoryManager(mDirector);
            mDirector.GetStoryManager.SetScreenManager(mScreenManager);
            mDirector.GetPathManager          = new PathManager();
            mDirector.GetDistributionDirector = new DistributionDirector(mDirector);
            mDirector.GetMilitaryManager      = new MilitaryManager(mDirector);
            mDirector.GetDeathManager         = new DeathManager();
            mDirector.GetActionManager        = new ActionManager();

            for (var i = 0; i < mScreenManager.GetScreenCount() - 1; i++)
            {
                mScreenManager.RemoveScreen();
            }
            LoadGameManagerScreen.OnReturnToMainMenuClicked(sender, eventArgs);
        }
Пример #4
0
        private void CollisionSystem_OnCollisionDetected(CollisionSystem system, ICollidable first, ICollidable second)
        {
            if (first is SnakeBit && second is Food food)
            {
                IncrementScore();

                _foods.Remove(food);
                _snake.GrowSnake();
                _collisionSystem.Remove(food);
            }
            else if (first is SnakeBit bit1 && second is SnakeBit bit2)
            {
                if (!_isGameOver)
                {
                    var screen = new GameOverScreen(_screenManager, _rendererWidth, _rendererHeight, _score);
                    _screenManager.AddScreen(screen);
                    _screenManager.RemoveScreen(this);

                    screen.Show();
                }

                _isGameOver = true;
            }
        }
        /// <summary>
        /// Updates the state of the LoadGameManager and changes to the game if the conditions are met.
        /// by the stack screen manager
        /// </summary>
        /// <param name="gametime"></param>
        public void Update(GameTime gametime)
        {
            if (mGameLoaded)
            {
                mGameLoaded = false;
            }

            if (sResolutionChanged)
            {
                sResolutionChanged = false;
            }

            switch (sPressed)
            {
            case "None":
                return;

            case "Skirmish":
                mLevel      = new Skirmish(mGraphics, ref mDirector, mContent, mScreenManager, LevelType.Skirmish);
                mGameScreen = mLevel.GameScreen;
                mUi         = mLevel.Ui;
                mNewGame    = true;
                break;

            case "TechDemo":
                mLevel      = new TechDemo(mGraphics, ref mDirector, mContent, mScreenManager, LevelType.Techdemo);
                mGameScreen = mLevel.GameScreen;
                mUi         = mLevel.Ui;
                mNewGame    = true;
                break;

            case "Tutorial":
                mLevel      = new Tutorial(mGraphics, ref mDirector, mContent, mScreenManager, LevelType.Tutorial);
                mGameScreen = mLevel.GameScreen;
                mUi         = mLevel.Ui;
                mNewGame    = true;
                break;

            case "Save1":
                mName = XSerializer.GetSaveNames()[0];
                break;

            case "Save2":
                mName = XSerializer.GetSaveNames()[1];
                break;

            case "Save3":
                mName = XSerializer.GetSaveNames()[2];
                break;

            case "Save4":
                mName = XSerializer.GetSaveNames()[3];
                break;

            case "Save5":
                mName = XSerializer.GetSaveNames()[4];
                break;

            case "ReturnToMainMenu":
                int width;
                int height;
                if (GlobalVariables.IsFullScreen)
                {
                    width  = mGame.mGraphicsAdapter.CurrentDisplayMode.Width;
                    height = mGame.mGraphicsAdapter.CurrentDisplayMode.Height;
                }
                else
                {
                    width  = GlobalVariables.ResolutionList[GlobalVariables.ChosenResolution].Item1;
                    height = GlobalVariables.ResolutionList[GlobalVariables.ChosenResolution].Item2;
                }

                mScreenManager.AddScreen(new MainMenuManagerScreen(screenResolution: new Vector2(width, height),
                                                                   screenManager: mScreenManager,
                                                                   director: ref mDirector,
                                                                   showSplash: false,
                                                                   game: mGame));
                break;

            default:
                throw new InvalidGenericArgumentException(
                          "Somehow the LoadGameManagerScreen was assigned to a button that he should not have been assigned to. Cannot handle" +
                          "this State");
            }

            //This means a save has to be loaded
            if (mName != "")
            {
                var levelToBe = XSerializer.Load(mName, false);
                if (levelToBe.IsPresent())
                {
                    mLevel = (ILevel)levelToBe.Get();
                    mLevel.ReloadContent(mContent, mGraphics, ref mDirector, mScreenManager);
                    mGameScreen = mLevel.GameScreen;
                    mUi         = mLevel.Ui;
                    //Remove all screens above this screen, of course this only works if this screen is really on the bottom of the stack
                    for (var i = mScreenManager.GetScreenCount() - 1; i > 1; i--)
                    {
                        mScreenManager.RemoveScreen();
                    }
                    mScreenManager.AddScreen(mGameScreen);
                    mScreenManager.AddScreen(mUi);
                    mDirector.GetStoryManager.SetScreenManager(mScreenManager);
                    mGameLoaded = true;
                    mName       = "";
                    GlobalVariables.mGameIsPaused = false;
                }
            }

            else if (mNewGame)
            {
                //Remove all screens above this screen, of course this only works if this screen is really on the bottom of the stack
                for (var i = mScreenManager.GetScreenCount() - 1; i > 0; i--)
                {
                    mScreenManager.RemoveScreen();
                }
                mScreenManager.AddScreen(mGameScreen);
                mScreenManager.AddScreen(mUi);

                mGameLoaded = true;
                mNewGame    = false;
                GlobalVariables.mGameIsPaused = false;
            }

            sPressed = "None";
        }
        /// <summary>
        /// Updates the state of the main menu and changes the screen that is currently being displayed
        /// by the stack screen manager
        /// </summary>
        /// <param name="gametime"></param>
        public void Update(GameTime gametime)
        {
            if (sResolutionChanged)
            {
                Initialize(sViewportResolution, sResolutionChanged, false, mGame);
                // LoadScreenContents(mContent);
                mScreenManager.RemoveScreen();
                mScreenManager.RemoveScreen();
                mMenuBackgroundScreen.TransitionTo(EScreen.OptionsScreen, EScreen.OptionsScreen, gametime);
                mScreenManager.AddScreen(mMenuBackgroundScreen);
                mScreenManager.AddScreen(mOptionsScreen);
                sResolutionChanged = false;
            }
            switch (mScreenState)
            {
            case EScreen.AchievementsScreen:
                if (sPressed == "Back")
                {
                    SwitchScreen(EScreen.MainMenuScreen, mAchievementsScreen, mMainMenuScreen, gametime);
                }
                break;

            case EScreen.GameModeSelectScreen:
                if (sPressed == "Back")
                {
                    SwitchScreen(EScreen.MainMenuScreen, mGameModeSelectScreen, mMainMenuScreen, gametime);
                }
                break;

            case EScreen.GameScreen:
                break;

            case EScreen.LoadSelectScreen:
                if (sPressed == "Load1")
                {
                    break;
                }
                if (sPressed == "Back")
                {
                    SwitchScreen(EScreen.MainMenuScreen, mLoadSelectScreen, mMainMenuScreen, gametime);
                }
                break;

            case EScreen.MainMenuScreen:
                if (sPressed == "Play")
                {
                    SwitchScreen(EScreen.GameModeSelectScreen, mMainMenuScreen, mGameModeSelectScreen, gametime);
                }

                if (sPressed == "Load")
                {
                    SwitchScreen(EScreen.LoadSelectScreen, mMainMenuScreen, mLoadSelectScreen, gametime);
                }

                if (sPressed == "Options")
                {
                    SwitchScreen(EScreen.OptionsScreen, mMainMenuScreen, mOptionsScreen, gametime);
                }

                if (sPressed == "Achievements")
                {
                    SwitchScreen(EScreen.AchievementsScreen, mMainMenuScreen, mAchievementsScreen, gametime);
                }

                if (sPressed == "Quit")
                {
                    mGame.Exit();
                }
                break;

            case EScreen.OptionsScreen:
                if (sPressed == "Back")
                {
                    SwitchScreen(EScreen.MainMenuScreen, mOptionsScreen, mMainMenuScreen, gametime);
                }
                break;

            case EScreen.SplashScreen:
                if (Keyboard.GetState().GetPressedKeys().Length > 0 ||
                    Mouse.GetState().LeftButton == ButtonState.Pressed ||
                    Mouse.GetState().RightButton == ButtonState.Pressed)
                {
                    sPressed = "Pressed";
                }

                if (sPressed == "Pressed")
                {
                    SwitchScreen(EScreen.MainMenuScreen, mSplashScreen, mMainMenuScreen, gametime);
                }

                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Пример #7
0
        /// <summary>
        /// The handle method of the Tutorial. Triggers events, like for examples infoboxes.
        /// </summary>
        private void HandleTutorial()
        {
            switch (mTutorialState)
            {
            case "Beginning":
                if (mTutorialScreen.TutorialState == "AwaitingUserAction")
                {
                    mTutorialState = "Settler";
                }
                break;

            case "Settler":
                if (mDirector.GetMilitaryManager.PlayerPlatformCount == 1)
                {
                    mTutorialState = "UI_FirstPlatform";
                    mTutorialScreen.TutorialState = "UI_FirstPlatform";
                }
                break;

            case "UI_FirstPlatform":
                if (mDirector.GetMilitaryManager.PlayerPlatformCount == 2)
                {
                    mTutorialState = "UI_SecondPlatform";
                    mTutorialScreen.TutorialState = "UI_SecondPlatform";
                }
                break;

            case "UI_SecondPlatform":
                if (mDirector.GetMilitaryManager.PlayerPlatformCount == 3)
                {
                    mTutorialState = "CivilUnits_Build";
                    mTutorialScreen.TutorialState = "CivilUnits_Build";
                }
                break;

            case "CivilUnits_Build":
                if (mDirector.GetDistributionDirector
                    .GetManager(StructureMap.GetPlatformList().First.Value.GetGraphIndex())
                    .GetNumberOfAssigned()[1] > 0)
                {
                    mTutorialState = "UserInterface_ProducePlatform";
                    mTutorialScreen.TutorialState = "UserInterface_ProducePlatform";
                }
                break;

            case "UserInterface_ProducePlatform":
                if (mDirector.GetDistributionDirector
                    .GetManager(StructureMap.GetPlatformList().First.Value.GetGraphIndex())
                    .GetNumberOfProdPlatforms() > 0)
                {
                    mTutorialState = "Factory";
                    mTutorialScreen.TutorialState = "Factory";
                }
                break;

            case "Factory":
                if (mDirector.GetDistributionDirector
                    .GetManager(StructureMap.GetPlatformList().First.Value.GetGraphIndex())
                    .GetNumberOfProdPlatforms() > 1)
                {
                    mTutorialState = "SelectedPlatform_ActionAssignment";
                    mTutorialScreen.TutorialState = "SelectedPlatform_ActionAssignment";
                }
                break;

            case "SelectedPlatform_ActionAssignment":
                if (mDirector.GetDistributionDirector
                    .GetManager(StructureMap.GetPlatformList().First.Value.GetGraphIndex())
                    .GetNumberOfAssigned()[1] < 1)
                {
                    mTutorialState = "CivilUnits_Logistics";
                    mTutorialScreen.TutorialState = "CivilUnits_Logistics";
                }
                break;

            case "CivilUnits_Logistics":
                if (mDirector.GetDistributionDirector
                    .GetManager(StructureMap.GetPlatformList().First.Value.GetGraphIndex()).GetNumberOfAssigned()[2] > 0)
                {
                    mTutorialState = "BuildGeneralUnit";
                    mTutorialScreen.TutorialState = "BuildGeneralUnit";
                }
                break;

            case "BuildGeneralUnit":
                if (mDirector.GetDistributionDirector
                    .GetManager(StructureMap.GetPlatformList().First.Value.GetGraphIndex()).GetNumberOfAssigned()[4] > 0)
                {
                    mTutorialState = "BuildDefenseBuilding";
                    mTutorialScreen.TutorialState = "BuildDefenseBuilding";
                }
                break;

            case "BuildDefenseBuilding":
                if (mDirector.GetDistributionDirector
                    .GetManager(StructureMap.GetPlatformList().First.Value.GetGraphIndex()).GetNumberOfAssigned()[3] == 0)
                {
                    mTutorialState = "Force-Deactivation";
                    mTutorialScreen.TutorialState = "Force-Deactivation";
                }
                break;

            case "Force-Deactivation":
                if (mDirector.GetDistributionDirector
                    .GetManager(StructureMap.GetPlatformList().First.Value.GetGraphIndex()).GetNumberOfAssigned()[4] == 0)
                {
                    mTutorialState = "Powerhouse";
                    mTutorialScreen.TutorialState = "Powerhouse";
                }
                break;

            case "Powerhouse":
                if (mDirector.GetDistributionDirector
                    .GetManager(StructureMap.GetPlatformList().First.Value.GetGraphIndex()).GetNumberOfAssigned()[0] > 0)
                {
                    mTutorialState = "Barracks";
                    mTutorialScreen.TutorialState = "Barracks";
                }
                break;

            case "Barracks":
                if (mDirector.GetDistributionDirector
                    .GetManager(StructureMap.GetPlatformList().First.Value.GetGraphIndex()).GetNumberOfAssigned()[2] > 2)
                {
                    mTutorialState = "create_MilitaryUnit";
                    mTutorialScreen.TutorialState = "create_MilitaryUnit";
                }
                break;

            case "create_MilitaryUnit":
                if (mDirector.GetMilitaryManager.PlayerUnitCount > 0)
                {
                    mTutorialState = "finalPopup";
                    mTutorialScreen.TutorialState = "finalPopup";
                }
                break;

            case "finalPopup":
                var assignedUnitsList = mDirector.GetDistributionDirector.GetManager(StructureMap.GetPlatformList().
                                                                                     First.Value.GetGraphIndex()).GetNumberOfAssigned();
                if (assignedUnitsList[0] == 0 && assignedUnitsList[1] == 0 && assignedUnitsList[2] == 0 && assignedUnitsList[3] == 0)
                {
                    mTutorialState = "EndOfTutorial";
                    mTutorialScreen.TutorialState = "EndOfTutorial  ";
                }
                break;

            case "EndOfTutorial":
                mTutorialState = "noAction";
                mScreenManager.RemoveScreen();
                Win();
                break;

            case "noAction":
                break;

            default:
                mTutorialScreen = new TutorialScreen(mDirector);
                mTutorialScreen.TutorialState = "Beginning";
                mTutorialState = "Beginning";
                mScreenManager.AddScreen(mTutorialScreen);
                break;
            }
        }
Пример #8
0
        /// <summary>
        /// Updates the state of the pause menu and changes the screen that is currently being displayed
        /// by the stack screen manager.
        /// </summary>
        /// <param name="gametime"></param>
        public void Update(GameTime gametime)
        {
            if (sPausedAgain)
            {
                mScreenManager.AddScreen(mGamePauseScreen);
                sPausedAgain = false;
            }

            if (sSaved)
            {
                mSaveGameScreen = new SaveGameScreen(mScreenResolution)
                {
                    mMenuOpacity = 1f
                };
                sPressed = "Save Game";
                Console.WriteLine("Save Screen Updated");
                sSaved = false;
            }

            switch (mScreenState)
            {
            case EScreen.GameScreen:
                break;

            case EScreen.GamePauseScreen:
                if (sPressed == "Resume")
                {
                    mScreenManager.RemoveScreen();
                    mScreenManager.RemoveScreen();
                    sPressed     = "None";
                    sPausedAgain = true;
                }

                if (sPressed == "Save Game")
                {
                    SwitchScreen(EScreen.SaveGameScreen, mGamePauseScreen, mSaveGameScreen, gametime);
                }

                if (sPressed == "Statistics")
                {
                    SwitchScreen(EScreen.StatisticsScreen, mGamePauseScreen, mStatisticsScreen, gametime);
                }

                if (sPressed == "Main Menu")
                {
                    mDirector.GetStoryManager.Level.GameScreen.Unload();
                    mDirector.GetClock       = new Clock();
                    mDirector.GetIdGenerator = new IdGenerator();
                    mDirector.GetInputManager.RemoveEverythingFromInputManager();
                    mDirector.GetStoryManager = new StoryManager(mDirector);
                    mDirector.GetStoryManager.SetScreenManager(mScreenManager);
                    mDirector.GetPathManager          = new PathManager();
                    mDirector.GetDistributionDirector = new DistributionDirector(mDirector);
                    mDirector.GetMilitaryManager      = new MilitaryManager(mDirector);
                    mDirector.GetDeathManager         = new DeathManager();
                    mDirector.GetActionManager        = new ActionManager();

                    for (var i = 0; i < mScreenManager.GetScreenCount() - 1; i++)
                    {
                        mScreenManager.RemoveScreen();
                    }
                }

                break;

            case EScreen.SaveGameScreen:
                if (sPressed == "Back")
                {
                    SwitchScreen(EScreen.GamePauseScreen, mSaveGameScreen, mGamePauseScreen, gametime);
                }

                if (sPressed == "Save Game")
                {
                    mScreenManager.RemoveScreen();
                    mScreenManager.AddScreen(mSaveGameScreen);
                    // SwitchScreen(EScreen.SaveGameScreen, mSaveGameScreen, mSaveGameScreen, gametime);
                    // SwitchScreen(EScreen.SaveGameScreen, mGamePauseScreen, mSaveGameScreen, gametime);
                    sPressed = "None";
                }

                if (sPressed == "Save1")
                {
                    mGameSaveStrings = XSerializer.GetSaveNames();
                    var path = @"%USERPROFILE%\Saved Games\Singularity\Saves";
                    if (mGameSaveStrings.Length >= 1)
                    {
                        path = Environment.ExpandEnvironmentVariables(path);
                        path = path + @"\" + mGameSaveStrings[0];
                    }

                    if (File.Exists(path))
                    {
                        File.Delete(path);
                    }

                    SaveGame();
                }

                if (sPressed == "Save2")
                {
                    mGameSaveStrings = XSerializer.GetSaveNames();
                    var path = @"%USERPROFILE%\Saved Games\Singularity\Saves";
                    if (mGameSaveStrings.Length >= 2)
                    {
                        path = Environment.ExpandEnvironmentVariables(path);
                        path = path + @"\" + mGameSaveStrings[1];
                    }

                    if (File.Exists(path))
                    {
                        File.Delete(path);
                    }

                    SaveGame();
                }

                if (sPressed == "Save3")
                {
                    mGameSaveStrings = XSerializer.GetSaveNames();
                    var path = @"%USERPROFILE%\Saved Games\Singularity\Saves";
                    if (mGameSaveStrings.Length >= 3)
                    {
                        path = Environment.ExpandEnvironmentVariables(path);
                        path = path + @"\" + mGameSaveStrings[2];
                    }

                    if (File.Exists(path))
                    {
                        File.Delete(path);
                    }

                    SaveGame();
                }

                if (sPressed == "Save4")
                {
                    mGameSaveStrings = XSerializer.GetSaveNames();
                    var path = @"%USERPROFILE%\Saved Games\Singularity\Saves";
                    if (mGameSaveStrings.Length >= 4)
                    {
                        path = Environment.ExpandEnvironmentVariables(path);
                        path = path + @"\" + mGameSaveStrings[3];
                    }

                    if (File.Exists(path))
                    {
                        File.Delete(path);
                    }

                    SaveGame();
                }

                if (sPressed == "Save5")
                {
                    mGameSaveStrings = XSerializer.GetSaveNames();
                    var path = @"%USERPROFILE%\Saved Games\Singularity\Saves";
                    if (mGameSaveStrings.Length >= 5)
                    {
                        path = Environment.ExpandEnvironmentVariables(path);
                        path = path + @"\" + mGameSaveStrings[4];
                    }

                    if (File.Exists(path))
                    {
                        File.Delete(path);
                    }

                    SaveGame();
                }

                break;

            case EScreen.StatisticsScreen:
                if (sPressed == "Back")
                {
                    SwitchScreen(EScreen.GamePauseScreen, mStatisticsScreen, mGamePauseScreen, gametime);
                }

                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }