public static XmlGameDataSection[] CreateSectionArray(XmlDocument doc) { var settlementNodes = doc.SelectNodes("/game/settlements/settlement"); var buildingSections = new XmlGameDataSection[settlementNodes.Count]; var builder = new XmlBuildingDataSectionFactory(); for (var index = 0; index < settlementNodes.Count; index++) { builder.SetValues(settlementNodes[index]); buildingSections[index] = new XmlGameDataSection(builder); } return(buildingSections); }
public static XmlGameDataSection[] CreateSectionArray(XmlDocument doc) { var roadsNodes = doc.SelectNodes("/game/roads/road"); var sections = new XmlGameDataSection[roadsNodes.Count]; var builder = new XmlRoadDataSectionFactory(); for (var index = 0; index < roadsNodes.Count; index++) { builder.SetValues(roadsNodes[index]); sections[index] = new XmlGameDataSection(builder); } return(sections); }
public XmlGameDataReader(Stream stream) { var sr = new StreamReader(stream); var content = sr.ReadToEnd(); var doc = new XmlDocument(); doc.LoadXml(content); this.sections = new Dictionary <GameDataSectionKeys, XmlGameDataSection>(); this.sectionArrays = new Dictionary <GameDataSectionKeys, XmlGameDataSection[]>(); var section = new XmlGameDataSection(new XmlGameBoardDataSectionFactory(doc)); this.sections.Add(GameDataSectionKeys.GameBoard, section); var playerNode = doc.DocumentElement.SelectSingleNode("/game/players/playerOne"); section = new XmlGameDataSection(new XmlGamePlayerDataSectionFactory(playerNode)); this.sections.Add(GameDataSectionKeys.PlayerOne, section); foreach (var token in new List <Tuple <String, GameDataSectionKeys> > { new Tuple <string, GameDataSectionKeys>("playerTwo", GameDataSectionKeys.PlayerTwo), new Tuple <string, GameDataSectionKeys>("playerThree", GameDataSectionKeys.PlayerThree), new Tuple <string, GameDataSectionKeys>("playerFour", GameDataSectionKeys.PlayerFour) }) { playerNode = doc.DocumentElement.SelectSingleNode("/game/players/" + token.Item1); if (playerNode == null) { continue; } section = new XmlGameDataSection(new XmlGamePlayerDataSectionFactory(playerNode)); this.sections.Add(token.Item2, section); } var sections = XmlBuildingsDataSectionFactory.CreateSectionArray(doc); this.sectionArrays.Add(GameDataSectionKeys.Buildings, sections); sections = XmlRoadsDataSectionFactory.CreateSectionArray(doc); this.sectionArrays.Add(GameDataSectionKeys.Roads, sections); }