public GameBoard(string pGameBoardFile, Player[] pPlayers) { System.Xml.XmlDocument xmlfile = new System.Xml.XmlDocument(); eActionType contextAction; Version fileVersion = new Version("0.0"); FreeParkingOwner = BANK; FreeJailOwner = BANK; xmlfile.Load(System.Environment.ExpandEnvironmentVariables(pGameBoardFile)); if (!Version.TryParse(xmlfile.SelectSingleNode("monopoly").Attributes["version"]?.InnerText, out fileVersion)) { fileVersion = new Version("0.0"); } if (fileVersion.Minor < 6) { throw new NotSupportedException("Gameboard Version to low"); } Settings = new Settings(xmlfile.SelectSingleNode("monopoly")); foreach (System.Xml.XmlNode xmlfield in xmlfile.SelectNodes("monopoly/fields/*")) { ushort contextCash; string contextName; contextName = xmlfield.Attributes.GetNamedItem("name")?.InnerText; ushort.TryParse(xmlfield.Attributes.GetNamedItem("cash")?.InnerText, out contextCash); switch (xmlfield.Name.ToLower()) { case "start": { FieldCol.Add(contextName, new Fields.Startfield(contextCash, contextName)); break; } case "house": { FieldCol.Add(contextName, new Fields.HouseField(xmlfield, Settings)); break; } case "chance": { var actionText = xmlfield.Attributes.GetNamedItem("action")?.InnerText.Split(','); eActionType[] actions = new eActionType[actionText.Length - 1 + 1]; for (int i = 0; i < actionText.Length; i++) { if (!(Enum.TryParse(actionText[i], out actions[i]))) { System.Diagnostics.Debug.WriteLine($"field {contextName} has unknown action {xmlfield.Attributes.GetNamedItem("action")?.InnerText}"); } } FieldCol.Add(contextName, new Fields.ChanceField(contextName, actions[0], contextCash)); break; } case "station": { FieldCol.Add(contextName, new Fields.StationField(contextName, contextCash)); break; } case "jail": { if (!Enum.TryParse(xmlfield.Attributes.GetNamedItem("action")?.InnerText, out contextAction)) { System.Diagnostics.Debug.WriteLine($"field {contextName} has unknown action {xmlfield.Attributes.GetNamedItem("action")?.InnerText}"); } FieldCol.Add(contextName, new Fields.JailField(contextName, contextAction)); break; } default: { FieldCol.Add(contextName, new Fields.ChanceField(contextName, eActionType.None, 0)); throw new NotSupportedException($"Fieldtype {nameof(xmlfield.Name)}={xmlfield.Name} not supported"); } } } if (Settings.UseWundertuete) { Wundertuete = new Entity("Wundertuete", System.Drawing.Color.White); } PlayerRank = pPlayers; Statistics = new StatisticsClass(this); }
public GameBoard(string pGameBoardFile, Players.Player[] pPlayers) { var xmldoc = new XmlDocument(); ushort contextCash; string contextName; eActionType contextAction; var fileVersion = new Version("0.0"); xmldoc.Load(Environment.ExpandEnvironmentVariables(pGameBoardFile)); Version.TryParse(xmldoc.SelectSingleNode("monopoly").Attributes["version"].InnerText, out fileVersion); if (fileVersion.Major < 6) throw new DotNetPolyException("Gameboard Version to low"); Setting = new Settings(xmldoc.SelectSingleNode("monopoly")); foreach (XmlNode xmlfield in xmldoc.SelectNodes("monopoly/fields/*")) { contextName = xmlfield.Attributes["name"].InnerText; ushort.TryParse(xmlfield.Attributes["cash"].InnerText, out contextCash); switch (xmlfield.Name.ToLower()) { case "start": FieldCol.Add(contextName, new StartField(contextCash, contextName)); break; case "house": FieldCol.Add(contextName, new HouseField(xmlfield, Setting)); break; case "chance": string[] actionText = xmlfield.Attributes["action"].InnerText.Split(','); eActionType[] actions = new eActionType[actionText.Length-1]; for (int i = 0; i < actionText.Length - 1; i++) if (!Enum.TryParse<eActionType>(actionText[i], out actions[i])) System.Diagnostics.Debug.WriteLine($"field {contextName} has unknown action {xmlfield.Attributes.GetNamedItem("action")?.InnerText}"); FieldCol.Add(contextName, new ChanceField(contextName, actions, contextCash)); break; case "station": FieldCol.Add(contextName, new StationField(contextName, contextCash)); break; case "jail": if (Enum.TryParse<eActionType>(xmlfield.Attributes["action"].InnerText, out contextAction)) System.Diagnostics.Debug.WriteLine($"field {contextName} has unknown action {xmlfield.Attributes.GetNamedItem("action")?.InnerText}"); FieldCol.Add(contextName, new JailField(contextName, contextAction); break; default: throw new DotNetPolyException($"Fieldtype {nameof(xmlfield.Name)}={xmlfield.Name} not supported"); } if (Setting.UseWundertuete) Wundertuete = new Players.Entity("Wundertuete", System.Drawing.Color.White); playerRank = pPlayers; Statistic = new Statistics(this); } }