예제 #1
0
 /// <summary>
 /// Saves the file in XML format to the given Stream.
 /// </summary>
 /// <param name="saveFile">Stream to pass in, usually from a SaveFileDialog, to which to save the file.</param>
 public void saveLevelXML(Stream saveFile)
 {
     FileStream fileStream = (FileStream)saveFile;//new FileStream(filepath, FileMode.OpenOrCreate);
     XmlSerializer xml = new XmlSerializer(typeof(LevelXML));
     LevelXML levelXML = new LevelXML();
     levelXML.Name = LevelName;
     levelXML.sizeX = simpleLevelGrid.SizeX;
     levelXML.sizeY = simpleLevelGrid.SizeY;
     for (int i = 0; i < levelXML.sizeX; ++i)
     {
         RowXML newRow = new RowXML();
         newRow.index = i;
         for (int j = 0; j < levelXML.sizeY; ++j)
         {
             ColumnXML newCol = new ColumnXML();
             newCol.index = j;
             newCol.type = simpleLevelGrid.GridSpaces[i, j].SpaceType;
             newCol.elevation = simpleLevelGrid.GridSpaces[i,j].Elevation;
             if (simpleLevelGrid.GridSpaces[i, j].IsOccupied)
             {
                 Actor temp = simpleLevelGrid.GridSpaces[i,j].CurrentActor;
                 if (temp is Hero)
                 {
                     Hero tempH = (Hero) temp;
                     newCol.hero = new HeroXML();
                     newCol.hero.name = tempH.Name;
                     newCol.hero.moveSpeed = tempH.MoveSpeed;
                     newCol.hero.currentEnergy = tempH.Energy;
                     newCol.hero.currentHP = tempH.Health;
                     newCol.hero.maxEnergy = tempH.MaxEnergy;
                     newCol.hero.maxHP = tempH.MaximumHealth;
                     newCol.hero.team = tempH.TeamIndex;
                     newCol.hero.classNum = tempH.ClassIndex;
                     newCol.hero.level = tempH.Level;
                 }
                 else if (temp is Person)
                 {
                     Person tempP = (Person)temp;
                     newCol.person = new PersonXML();
                     newCol.person.name = tempP.Name;
                     newCol.person.moveSpeed = tempP.MoveSpeed;
                     newCol.person.currentEnergy = tempP.Energy;
                     newCol.person.currentHP = tempP.Health;
                     newCol.person.maxEnergy = tempP.MaxEnergy;
                     newCol.person.maxHP = tempP.MaximumHealth;
                 }
                 else
                 {
                     newCol.actor = new ActorXML();
                     newCol.actor.name = temp.Name;
                 }
                 newCol.costNorth = simpleLevelGrid.withinGrid(i, j - 1) ? simpleLevelGrid.MoveCosts[i, j, i, j - 1] : 0;
                 newCol.costNorthEast = simpleLevelGrid.withinGrid(i + 1, j + (i % 2 == 0 ? -1 : 0)) ? simpleLevelGrid.MoveCosts[i, j, i + 1, j + (i % 2 == 0 ? -1 : 0)] : 0;
                 newCol.costNorthWest = simpleLevelGrid.withinGrid(i - 1, j + (i % 2 == 0 ? -1 : 0)) ? simpleLevelGrid.MoveCosts[i, j, i - 1, j + (i % 2 == 0 ? -1 : 0)] : 0;
                 newCol.costSouth = simpleLevelGrid.withinGrid(i, j - 1) ? simpleLevelGrid.MoveCosts[i, j, i, j - 1] : 0;
                 newCol.costSouthEast = simpleLevelGrid.withinGrid(i + 1, j + (i % 2 == 0 ? 0 : 1)) ? simpleLevelGrid.MoveCosts[i, j, i + 1, j + (i % 2 == 0 ? 0 : 1)] : 0;
                 newCol.costSouthWest = simpleLevelGrid.withinGrid(i - 1, j + (i % 2 == 0 ? 0 : 1)) ? simpleLevelGrid.MoveCosts[i, j, i - 1, j + (i % 2 == 0 ? 0 : 1)] : 0;
                 for (int k = 0; k < 3; ++k)
                 {
                     WallXML newWall = new WallXML();
                     newWall.direction = k;
                     newWall.type = simpleLevelGrid.GridSpaces[i, j].Walls[k].WallType;
                     newCol.walls.Add(newWall);
                 }
             }
             newRow.columns.Add(newCol);
         }
         levelXML.rows.Add(newRow);
     }
     xml.Serialize(fileStream, levelXML);
     fileStream.Close();
 }
예제 #2
0
        /// <summary>
        /// Saves the file in XML format to the given Stream.
        /// </summary>
        /// <param name="saveFile">Stream to pass in, usually from a SaveFileDialog, to which to save the file.</param>
        public void saveLevelXML(Stream saveFile)
        {
            FileStream    fileStream = (FileStream)saveFile;//new FileStream(filepath, FileMode.OpenOrCreate);
            XmlSerializer xml        = new XmlSerializer(typeof(LevelXML));
            LevelXML      levelXML   = new LevelXML();

            levelXML.Name  = LevelName;
            levelXML.sizeX = simpleLevelGrid.SizeX;
            levelXML.sizeY = simpleLevelGrid.SizeY;
            for (int i = 0; i < levelXML.sizeX; ++i)
            {
                RowXML newRow = new RowXML();
                newRow.index = i;
                for (int j = 0; j < levelXML.sizeY; ++j)
                {
                    ColumnXML newCol = new ColumnXML();
                    newCol.index     = j;
                    newCol.type      = simpleLevelGrid.GridSpaces[i, j].SpaceType;
                    newCol.elevation = simpleLevelGrid.GridSpaces[i, j].Elevation;
                    if (simpleLevelGrid.GridSpaces[i, j].IsOccupied)
                    {
                        Actor temp = simpleLevelGrid.GridSpaces[i, j].CurrentActor;
                        if (temp is Hero)
                        {
                            Hero tempH = (Hero)temp;
                            newCol.hero               = new HeroXML();
                            newCol.hero.name          = tempH.Name;
                            newCol.hero.moveSpeed     = tempH.MoveSpeed;
                            newCol.hero.currentEnergy = tempH.Energy;
                            newCol.hero.currentHP     = tempH.Health;
                            newCol.hero.maxEnergy     = tempH.MaxEnergy;
                            newCol.hero.maxHP         = tempH.MaximumHealth;
                            newCol.hero.team          = tempH.TeamIndex;
                            newCol.hero.classNum      = tempH.ClassIndex;
                            newCol.hero.level         = tempH.Level;
                        }
                        else if (temp is Person)
                        {
                            Person tempP = (Person)temp;
                            newCol.person               = new PersonXML();
                            newCol.person.name          = tempP.Name;
                            newCol.person.moveSpeed     = tempP.MoveSpeed;
                            newCol.person.currentEnergy = tempP.Energy;
                            newCol.person.currentHP     = tempP.Health;
                            newCol.person.maxEnergy     = tempP.MaxEnergy;
                            newCol.person.maxHP         = tempP.MaximumHealth;
                        }
                        else
                        {
                            newCol.actor      = new ActorXML();
                            newCol.actor.name = temp.Name;
                        }
                        newCol.costNorth     = simpleLevelGrid.withinGrid(i, j - 1) ? simpleLevelGrid.MoveCosts[i, j, i, j - 1] : 0;
                        newCol.costNorthEast = simpleLevelGrid.withinGrid(i + 1, j + (i % 2 == 0 ? -1 : 0)) ? simpleLevelGrid.MoveCosts[i, j, i + 1, j + (i % 2 == 0 ? -1 : 0)] : 0;
                        newCol.costNorthWest = simpleLevelGrid.withinGrid(i - 1, j + (i % 2 == 0 ? -1 : 0)) ? simpleLevelGrid.MoveCosts[i, j, i - 1, j + (i % 2 == 0 ? -1 : 0)] : 0;
                        newCol.costSouth     = simpleLevelGrid.withinGrid(i, j - 1) ? simpleLevelGrid.MoveCosts[i, j, i, j - 1] : 0;
                        newCol.costSouthEast = simpleLevelGrid.withinGrid(i + 1, j + (i % 2 == 0 ? 0 : 1)) ? simpleLevelGrid.MoveCosts[i, j, i + 1, j + (i % 2 == 0 ? 0 : 1)] : 0;
                        newCol.costSouthWest = simpleLevelGrid.withinGrid(i - 1, j + (i % 2 == 0 ? 0 : 1)) ? simpleLevelGrid.MoveCosts[i, j, i - 1, j + (i % 2 == 0 ? 0 : 1)] : 0;
                        for (int k = 0; k < 3; ++k)
                        {
                            WallXML newWall = new WallXML();
                            newWall.direction = k;
                            newWall.type      = simpleLevelGrid.GridSpaces[i, j].Walls[k].WallType;
                            newCol.walls.Add(newWall);
                        }
                    }
                    newRow.columns.Add(newCol);
                }
                levelXML.rows.Add(newRow);
            }
            xml.Serialize(fileStream, levelXML);
            fileStream.Close();
        }