Пример #1
0
        public void SaveContent(GameState gameState)
        {
            if (gameState != null)
            {
                ////XML speichert nun ein Objekt von GameState welches sowhol die aktuelle Gruppe als auch die aktuelle Scene speichert
                //XmlSerializer xmlSerializerGroup = new XmlSerializer(typeof(GameState));
                ////Um sicher zu stellen das der Pfad bereits angelegt wurde wird hier die Property genutzt
                ////Ständige überprüfung bei jedem Speichern somit wird der Fehler behoben falls jemand wärend der Laufzeit den Ordner löscht behoben
                //StreamWriter sw = new StreamWriter(SavePath+@"/SafeData.xml");
                //xmlSerializerGroup.Serialize(sw,gameState);
                //sw.Close();

                XmlWriterSettings settings = new XmlWriterSettings()
                {
                    Indent = true,
                    Encoding = Encoding.UTF8
                };
                using (XmlWriter xml_writer = XmlWriter.Create(SavePath + @"/SafeData.xml", settings))
                {
                    xml_writer.WriteStartDocument();
                    xml_writer.WriteStartElement("Document");
                    foreach (PartyMember chars in gameState.getGroup())
                    {
                        xml_writer.WriteStartElement("Member");
                        xml_writer.WriteElementString("Name", chars.Name.ToLower());
                        xml_writer.WriteElementString("Level", "" + chars.Level);
                        xml_writer.WriteEndElement();
                    }

                    xml_writer.WriteStartElement("Scene");
                    xml_writer.WriteElementString("Nummer", "" + gameState.getSceneCount());
                    xml_writer.WriteEndElement();
                    xml_writer.WriteEndDocument();
                }

            }
            else
            {
                //Öffne ein Menü zum verarbeiten des Fehlers oder sperre den Knopf
            }
        }
Пример #2
0
 public SaveEvent(GameState gameState)
 {
     this.SavePath = @"SaveGame";
     SaveContent(gameState);
 }
Пример #3
0
        public void Update(GameTime gameTime)
        {
            if (gameState != GameState.mainMenu && gameState != GameState.intro)
            {
                activeScene = manager.sceneCounter;
                activeGroup = manager.Group;
            }

            if (options.clickedButton == LoadContentHelper.SaveButton.AssetName)
            {
                saveGame = new Events.GameState(activeGroup, activeScene);
                SaveEvent save = new SaveEvent(saveGame);
                options.clickedButton = "";
                gameState = GameState.inGame;
            }
            if(mainMenu.ClickedButton == LoadContentHelper.LoadGameButton.AssetName)
            {
                LoadEvent Load = new LoadEvent();

                foreach(Member member in Load.LoadChars())
                {
                    foreach(PartyMember partyMember in LoadContentHelper.AllCharacters )
                    {
                        if(member.name.ToLower() == partyMember.Name.ToLower())
                        {
                            partyMember.Level = Convert.ToInt32(member.lvl);
                            partyMember.SetMember();
                            activeGroup.Add(partyMember);
                            break;
                        }
                    }

                }

                this.activeScene = System.Int32.Parse(Load.LoadScene());

                manager = new GameManager(activeScene, activeGroup);
                mainMenu.ClickedButton = "";
                gameState = GameState.inGame;
            }
            if (mainMenu.ClickedButton == LoadContentHelper.NewGameButton.AssetName)
            {
                manager = new GameManager(0);
                mainMenu.ClickedButton = "";
                gameState = GameState.inGame;
            }
            this.controls.Update();

            //Wenn das options Menu geöffnet wird, wird der Gamestate gespeichert um nach dem pausieren fortzufahren
            if (this.controls.CurrentKeyboardState.IsKeyDown(Keys.Escape) && gameState != GameState.mainMenu && gameState != GameState.options)
            {
                this.oldGameState = gameState;
                gameState = GameState.options;
            }
            if(options.StateChanged)
            {
                this.gameState = GameState.inGame;
                options.StateChanged = false;
            }
            if (mainMenu.StateChanged)
            {
                if(mainMenu.ClickedButton == LoadContentHelper.NewGameButton.AssetName)
                {
                    gameState = GameState.inGame;
                }
                this.stateChanged = true;
                mainMenu.StateChanged = false;
            }
            //Je nach gamestate startet ein anderes Lied
            if (this.stateChanged || mainMenu.StateChanged || options.StateChanged)
            {
                MediaPlayer.Stop();
                switch (gameState)
                {
                    case GameState.mainMenu:
                        MediaPlayer.Play(this.mainMenuTheme);
                        break;
                    case GameState.options:
                        MediaPlayer.Play(this.battleScreenTheme);
                        break;
                    case GameState.inGame:
                        MediaPlayer.Play(this.battleScreenTheme);
                        break;
                }
                this.stateChanged = false;
            }

            //nachdem Das Intro abgespielt wurde, startet die Backgroundmusic
            if (gameTime.TotalGameTime.Seconds == 6)
            {
                if (gameState == GameState.intro)
                {
                    gameState = GameState.mainMenu;
                    stateChanged = true;
                }
            }

            switch (gameState)
            {
                case GameState.intro:
                    this.Intro.Update();
                    if(controls.CurrentKeyboardState.IsKeyDown(Keys.Enter) && !controls.PreviousKeyboardState.IsKeyDown(Keys.Enter) || controls.CurrentMouseState.LeftButton == ButtonState.Pressed && controls.PreviousMouseState.LeftButton != ButtonState.Pressed || controls.CurrentGamePadState.Buttons.A == ButtonState.Pressed && controls.PreviousGamePadState.Buttons.A != ButtonState.Pressed)
                    {
                        Intro.Player.Stop();
                        gameState = GameState.mainMenu;
                        stateChanged = true;
                    }
                    break;
                case GameState.mainMenu:
                    mainMenu.Update();
                        break;
                case GameState.options:
                    options.Update();
                    break;
                case GameState.inGame:
                    manager.Update(gameTime);
                    break;
            }
        }