using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Otter; namespace OtterApp { class SceneHandler : Scene { Dictionary availableScenes; int activeSceneID = 0; public SceneHandler() { availableScenes = new Dictionary(); GameScene DefaultScene = new GameScene("Default"); AddGraphic(DefaultScene.getGraphics()); availableScenes.Add("Default",DefaultScene); //TestScenes //createScene("Scene1"); //createScene("Scene2"); //createScene("Scene3"); } public void createScene(string titel) { if (!availableScenes.ContainsKey(titel)) { GameScene temp = new GameScene(titel); availableScenes.Add(temp.SCENENAME, temp); Console.WriteLine("{0} was created", titel); } else Console.WriteLine("Error - Scene Name is allready used"); } private void loadScene(String loadSceneKey) { // loaded scene to adapt graphics & entities GameScene loadScene; availableScenes.TryGetValue(loadSceneKey, out loadScene); // only proceed if scene is enlisted if (availableScenes.ContainsValue(loadScene)) { //reset graphics and entities this.RemoveAll(); List EntitiesToAdd = loadScene.GetEntitiesAll(); //adapt the loaded scenes graphics this.SetGraphic(loadScene.getGraphics()); //adapt the loaded scenes entites foreach (Entity copyEntity in EntitiesToAdd) { this.Add(copyEntity); } Console.WriteLine("{0} was loaded",loadScene.SCENENAME); } else Console.WriteLine("Error - Scene '{0}' could not be loaded", loadSceneKey); } public void deleteScene(string titel) { if (availableScenes.ContainsKey(titel)) availableScenes.Remove(titel); else Console.WriteLine("Error - Scene Name is not enlisted"); } public Scene getCurrentScene() { return availableScenes.ElementAt(activeSceneID).Value; } public void addEntity(List entityToAdd) { //funtzt nich eventuell entityToAdd als public list in gamescene oder hier einbauen damit bei loadscene eingebaut werden kann was in der scene gespeichert war //soll dafür sorgen dass scene "on the fly" neue entities und graphics hinzugefügt werden kann String tempKey = availableScenes.ElementAt(activeSceneID).Key; availableScenes.Remove(availableScenes.ElementAt(activeSceneID).Key); GameScene sceneToAdd = new GameScene(tempKey, entityToAdd); availableScenes.Add(tempKey, sceneToAdd); loadScene(tempKey); } public String getNextScene() { // increase Id of current Scene activeSceneID++; // If end of list reset to begin of list if (activeSceneID == availableScenes.Count) activeSceneID = 0; //return scene return availableScenes.ElementAt(activeSceneID).Key; } public override void Update() { base.Update(); if (Input.KeyPressed(Key.Space)) { // When the space bar is pressed switch to the FirstScene. //Game.SwitchScene(getNextScene()); loadScene(getNextScene()); } } } }