예제 #1
0
        /// <summary>
        /// Initializes game from a given map
        /// </summary>
        /// <returns>returns true if successful, else false</returns>
        public void LoadMap(Map map)
        {
            UnloadGame();
              GameLogic gameLogic = GameLogic.GetInstance();
              gameLogic.SetMap(map);

              // already initialised sectorManager by setting new map
              //gameLogic.SectorManager = new UnitSectorManager(map.GetWidth(), map.GetHeight());
              CollisionManager collisionManager = new CollisionManager();
              collisionManager.Init();
              gameLogic.SetCollisionManager(collisionManager);
              gameLogic.SuperFogManager = new SuperFogManager();
              PlayerFogManager playerFogManager = new PlayerFogManager();
              playerFogManager.Init();
              gameLogic.SuperFogManager.PlayerFogManager = playerFogManager;
              PcFogManager pcFogManager = new PcFogManager();
              pcFogManager.Init();
              gameLogic.SuperFogManager.PcFogManager = pcFogManager;

              GameObjectManager objectManager = GameObjectManager.GetInstance();
              IEnumerable<GameObject> list = map.GetGameObjects();
              foreach (GameObject obj in list)
              {
              objectManager.AddUnit(obj);
              }
              Debug.Assert(map != null);

              PathFinder.GetInstance().LoadMeshFromObstructions(map.GetWidth(), map.GetHeight(),
                                                            GlobalValues.GetInstance().MeshScale);

              // hinzugefügt von jonas (ka ob das wo besser passt)
              view.HumanView.GetInstance().GetRenderer().GetCamera().SetBoundaries(new Rectangle(0, 0, map.GetWidth(), map.GetHeight()));
        }
예제 #2
0
        /// <summary>
        /// Tries to load an old game.
        /// </summary>
        /// <param name="path">the file to load from</param>
        /// <returns>true if loading was successful, else false</returns>
        internal bool LoadGame(string path)
        {
            if (File.Exists(path))
              {
              // Unload previous game:
              UnloadGame();

              Stream fileStream = File.Open(path, FileMode.Open, FileAccess.Read);
              BinaryFormatter bf = new BinaryFormatter();
              object obj = bf.Deserialize(fileStream);
              Map map = (Map)obj;
              obj = bf.Deserialize(fileStream);
              Stats stats = (Stats)obj;
              List<GameObject> units = new List<GameObject>();

              while (fileStream.Position < fileStream.Length)
              {
                  obj = bf.Deserialize(fileStream);
                  Debug.WriteLine("Deserialized one object.");
                  units.Add((GameObject)obj);
              }
              fileStream.Close();
              GameLogic gameLogic = GameLogic.GetInstance();
              GlobalValues globalValues = GlobalValues.GetInstance();
              gameLogic.SetMap(map);
              //gameLogic.SectorManager = new UnitSectorManager(globalValues.mUnitSectorWidth,
              //      globalValues.mUnitSectorHeight, map.GetWidth(), map.GetHeight());
              CollisionManager collisionManager = new CollisionManager();
              collisionManager.Init();
              gameLogic.SetCollisionManager(collisionManager);
              gameLogic.SuperFogManager = new SuperFogManager();
              PlayerFogManager playerFogManager = new PlayerFogManager();
              playerFogManager.Init();
              gameLogic.SuperFogManager.PlayerFogManager = playerFogManager;
              PcFogManager pcFogManager = new PcFogManager();
              pcFogManager.Init();
              gameLogic.SuperFogManager.PcFogManager = pcFogManager;
              GameObjectManager gameObjectManager = GameObjectManager.GetInstance();
              foreach (GameObject unit in units)
              {
                  gameObjectManager.AddUnit(unit);
              }
              gameObjectManager.Stats = stats;
              PathFinder.GetInstance().LoadMeshFromObstructions(
                  map.GetWidth(),
                  map.GetHeight(),
                  globalValues.MeshScale);

              return true;
              }
              Debug.WriteLine("Spielstand existiert nicht!");
              return false;
        }
예제 #3
0
 private static void InheritanceTest()
 {
     Interceptor iceptor = new Interceptor(new Vector2(0, 0), Allegiance.Player);
     CollisionManager colMan = new CollisionManager();
     PlayerFogManager playerFogMan = new PlayerFogManager();
     PcFogManager pcFogMan = new PcFogManager();
     iceptor.SetQuadNode(typeof(CollisionManager), new QuadNode(null, colMan));
     iceptor.SetQuadNode(typeof(PlayerFogManager), new QuadNode(null, playerFogMan));
     iceptor.SetQuadNode(typeof(PcFogManager), new QuadNode(null, pcFogMan));
     Debug.Assert(iceptor.GetQuadNode(typeof(CollisionManager)).mManager
         != iceptor.GetQuadNode(typeof(PlayerFogManager)).mManager
         && iceptor.GetQuadNode(typeof(PlayerFogManager)).mManager
         != iceptor.GetQuadNode(typeof(PcFogManager)).mManager);
     Debug.WriteLine(iceptor.GetQuadNode(typeof(CollisionManager)).mManager);
     Debug.WriteLine(iceptor.GetQuadNode(typeof(PlayerFogManager)).mManager);
     Debug.WriteLine(iceptor.GetQuadNode(typeof(PcFogManager)).mManager);
     GameLogic.GetInstance().GetGameStateManager().UnloadGame();
 }