public AttackPattern PopulateAttackPattern(AttackPattern pattern) { XmlDocument xml = new XmlDocument(); xml.Load("D:\\VS 2010 Projects\\Shooter\\Shooter\\ShooterContent\\AttackPatterns\\" + pattern.m_id + ".xml"); XmlNode root = xml.FirstChild; XmlNode child; XmlAttributeCollection attributes; float endX = 0; float endY = 0; float moveX = 0; float moveY = 0; float speedX = 0; float speedY = 0; float waitTime = 0; float exitSpeed = 0; if (root == null) { return null; } attributes = root.Attributes; try { exitSpeed = Convert.ToInt32(attributes.GetNamedItem("exitSpeed").Value); } catch (FormatException e) { Console.WriteLine("AttackPattern exitSpeed: Input string is not a sequence of digits."); } catch (OverflowException e) { Console.WriteLine("AttackPattern exitSpeed: The number cannot fit in a float."); } pattern.SetExitSpeed(exitSpeed); if (root.HasChildNodes) { for (int j = 0; j < root.ChildNodes.Count; j++) { child = root.ChildNodes[j]; attributes = child.Attributes; try { moveX = Convert.ToInt32(attributes.GetNamedItem("moveX").Value); } catch (FormatException e) { Console.WriteLine("AttackPattern moveX: Input string is not a sequence of digits."); } catch (OverflowException e) { Console.WriteLine("AttackPattern moveX: The number cannot fit in a float."); } try { moveY = Convert.ToInt32(attributes.GetNamedItem("moveY").Value); } catch (FormatException e) { Console.WriteLine("AttackPattern moveY: Input string is not a sequence of digits."); } catch (OverflowException e) { Console.WriteLine("AttackPattern moveY: The number cannot fit in a float."); } try { speedX = Convert.ToInt32(attributes.GetNamedItem("speedX").Value); } catch (FormatException e) { Console.WriteLine("AttackPattern speedX: Input string is not a sequence of digits."); } catch (OverflowException e) { Console.WriteLine("AttackPattern speedX: The number cannot fit in a float."); } try { speedY = Convert.ToInt32(attributes.GetNamedItem("speedY").Value); } catch (FormatException e) { Console.WriteLine("AttackPattern speedY: Input string is not a sequence of digits."); } catch (OverflowException e) { Console.WriteLine("AttackPattern speedY: The number cannot fit in a float."); } try { waitTime = Convert.ToSingle(attributes.GetNamedItem("wait").Value); } catch (FormatException e) { Console.WriteLine("AttackPattern wait: Input string is not a sequence of digits."); } catch (OverflowException e) { Console.WriteLine("AttackPattern wait: The number cannot fit in a float."); } pattern.AddManuver(pattern.m_startX + moveX, pattern.m_startY + moveY, speedX, speedY, waitTime); } } else { Console.WriteLine("AttackPattern root: could not find children"); } return pattern; }
public AttackPattern PopulateAttackPattern(AttackPattern pattern) { XmlDocument xml = new XmlDocument(); xml.Load("D:\\VS 2010 Projects\\Shooter\\Shooter\\ShooterContent\\AttackPatterns\\" + pattern.m_id + ".xml"); XmlNode root = xml.FirstChild; XmlNode child; XmlAttributeCollection attributes; float endX = 0; float endY = 0; float moveX = 0; float moveY = 0; float speedX = 0; float speedY = 0; float waitTime = 0; float exitSpeed = 0; if (root == null) { return(null); } attributes = root.Attributes; try { exitSpeed = Convert.ToInt32(attributes.GetNamedItem("exitSpeed").Value); } catch (FormatException e) { Console.WriteLine("AttackPattern exitSpeed: Input string is not a sequence of digits."); } catch (OverflowException e) { Console.WriteLine("AttackPattern exitSpeed: The number cannot fit in a float."); } pattern.SetExitSpeed(exitSpeed); if (root.HasChildNodes) { for (int j = 0; j < root.ChildNodes.Count; j++) { child = root.ChildNodes[j]; attributes = child.Attributes; try { moveX = Convert.ToInt32(attributes.GetNamedItem("moveX").Value); } catch (FormatException e) { Console.WriteLine("AttackPattern moveX: Input string is not a sequence of digits."); } catch (OverflowException e) { Console.WriteLine("AttackPattern moveX: The number cannot fit in a float."); } try { moveY = Convert.ToInt32(attributes.GetNamedItem("moveY").Value); } catch (FormatException e) { Console.WriteLine("AttackPattern moveY: Input string is not a sequence of digits."); } catch (OverflowException e) { Console.WriteLine("AttackPattern moveY: The number cannot fit in a float."); } try { speedX = Convert.ToInt32(attributes.GetNamedItem("speedX").Value); } catch (FormatException e) { Console.WriteLine("AttackPattern speedX: Input string is not a sequence of digits."); } catch (OverflowException e) { Console.WriteLine("AttackPattern speedX: The number cannot fit in a float."); } try { speedY = Convert.ToInt32(attributes.GetNamedItem("speedY").Value); } catch (FormatException e) { Console.WriteLine("AttackPattern speedY: Input string is not a sequence of digits."); } catch (OverflowException e) { Console.WriteLine("AttackPattern speedY: The number cannot fit in a float."); } try { waitTime = Convert.ToSingle(attributes.GetNamedItem("wait").Value); } catch (FormatException e) { Console.WriteLine("AttackPattern wait: Input string is not a sequence of digits."); } catch (OverflowException e) { Console.WriteLine("AttackPattern wait: The number cannot fit in a float."); } pattern.AddManuver(pattern.m_startX + moveX, pattern.m_startY + moveY, speedX, speedY, waitTime); } } else { Console.WriteLine("AttackPattern root: could not find children"); } return(pattern); }