예제 #1
0
        public NewLevelGenerator()
        {
            rand = new Random();

            SetDepth(1);
            _branch = Dungeon_Branches.CATACOMBS;

            ResetGenerator();
        }
예제 #2
0
 private int GetIndexOfLocation(Dungeon_Branches branch, int depth)
 {
     for (int i = 0; i < _locations.Count; i++)
     {
         if (_locations[i].Item1 == branch && _locations[i].Item2 == depth)
         {
             return(i);
         }
     }
     return(-1);
 }
예제 #3
0
        public LevelData LoadLevel(Dungeon_Branches branch, int depth)
        {
            //TODO: This should really load a COPY, not the actual reference cause that might cause weird behavior?
            LevelData lvl          = null;
            int       indexOfLevel = GetIndexOfLocation(branch, depth);

            if (indexOfLevel >= 0)
            {
                lvl = _levels[indexOfLevel];
            }
            return(lvl);
        }
예제 #4
0
        public LevelData GenerateLevel(Dungeon_Branches branch, int depth)
        {
            _branch = branch;
            _depth  = depth;
            ResetGenerator();

            while (!_finished)
            {
                ExecuteNextStep();
            }

            return(GetLevelData());
        }
예제 #5
0
        public void SaveLevel(Dungeon_Branches branch, int depth, LevelData level)
        {
            int indexOfLevel = GetIndexOfLocation(branch, depth);

            if (indexOfLevel >= 0)
            {
                _levels[indexOfLevel] = level;
            }
            else
            {
                _levels.Add(level);
                _locations.Add(new Tuple <Dungeon_Branches, int>(branch, depth));
            }
        }
예제 #6
0
        public void UseStairs(IntVector2 position)
        {
            Dungeon_Branches destinationBranch = Dungeon_Branches.CELLAR;
            int destinationDepth = -1;

            foreach (StairsData s in _currentLevel.stairs)
            {
                if (s.x == position.X && s.y == position.Y)
                {
                    destinationBranch = (Dungeon_Branches)s.branch;
                    destinationDepth  = s.depth;
                }
            }
            if (destinationDepth == 0)
            {
                _gameOver = true;
            }
            else if (destinationDepth != -1)
            {
                GotoLevel(destinationBranch, destinationDepth);
            }
        }
예제 #7
0
        public void GotoLevel(Dungeon_Branches branch, int depth)
        {
            //TODO: Any spells affecting monsters on the previous level need to be shut off!

            //Save the player
            Student s = (Student)_gameObjectPool.GetActor(_studentID);

            //Save the player's ActorBehaviors
            List <ActorBehavior> studentBehaviors = new List <ActorBehavior>();

            foreach (int bID in s.GetBehaviors())
            {
                studentBehaviors.Add(_gameObjectPool.GetActorBehavior(bID));
            }

            //Save the current level
            if (_currentDepth != 0)
            {
                _dungeon.SaveLevel(_currentDungeonBranch, _currentDepth, SaveLevelToData());
            }

            //Reset the game object pool and turn counter objects
            _gameObjectPool.ResetGameObjectPool();
            _turnCounter.ClearTurnCounter();

            //Move all the student stuff into the new game object pool
            //TODO: Do this instead: Save the student as a data object properly, with its behaviors
            //And then load it into the level normally, as if the player loaded a saved game
            _gameObjectPool.AddObjectToPool(s, _studentID); //TODO: This is hack-y and should be changed somehow
            _turnCounter.AddObjectToCounter(_studentID);
            foreach (ActorBehavior b in studentBehaviors)
            {
                _gameObjectPool.AddObjectToPool(b, b.InstanceID);
            }

            //Build level
            _currentLevel = _dungeon.LoadLevel(branch, depth);
            if (_currentLevel == null)
            {
                _currentLevel = _gen.GenerateLevel(branch, depth);
            }
            LoadLevelFromData(_currentLevel);

            IntVector2 playerStart = new IntVector2(5, 5);

            //Place the player at the proper location
            if (_currentDepth > depth)
            {
                //Player climbed up, put the player on the down stairs
                IntVector2 tile = _map.GetFirstTileWithFeature(Tile_SimpleFeatureType.STAIRS_DOWN);
                if (tile != null)
                {
                    playerStart = tile;
                }
            }
            else
            {
                //Player went down, put the player on the up stairs
                IntVector2 tile = _map.GetFirstTileWithFeature(Tile_SimpleFeatureType.STAIRS_UP);
                if (tile != null)
                {
                    playerStart = tile;
                }
            }



            _gameObjectPool.GetActor(_studentID).WarpToPosition(playerStart);

            _currentDepth = depth;
            if (_currentDepth > _maxDepth)
            {
                _maxDepth = _currentDepth;
            }

            //A hacky way to make the levels look unique
            _map.ColorTiles(_currentDepth);
        }