private void LoadFromXML(XElement xEntity) { LifeCount = (int)xEntity.Attribute("Life"); _stepSize = (int)xEntity.Attribute("StepSize"); _movePattern = xEntity.Attribute("MovePattern") != null ? (MovePattern)Enum.Parse(typeof(MovePattern), xEntity.Attribute("MovePattern").Value) : _movePattern; int centerRow = xEntity.Attribute("CenterRow") != null? int.Parse(xEntity.Attribute("CenterRow").Value) : -1; int centerCol = xEntity.Attribute("CenterCol") != null? int.Parse(xEntity.Attribute("CenterCol").Value) : -1; if (centerRow != -1 && centerCol != -1) { _circleCenter = new Position(centerRow, centerCol); } _isClockwise = xEntity.Attribute("_isClockwise") != null? bool.Parse(xEntity.Attribute("_isClockwise").Value) : _isClockwise; _movePace = xEntity.Attribute("MovePace") != null ? (MovePace)Enum.Parse(typeof(MovePace), xEntity.Attribute("MovePace").Value) : _movePace; StepInterval = xEntity.Attribute("StepInterval") != null? int.Parse(xEntity.Attribute("StepInterval").Value) : StepInterval; _playerTarget = xEntity.Attribute("PlayerTarget") != null ? (PlayerTarget)Enum.Parse(typeof(PlayerTarget), xEntity.Attribute("PlayerTarget").Value) : _playerTarget; _stepQuantum = xEntity.Attribute("StepQuantum") != null? int.Parse(xEntity.Attribute("StepQuantum").Value) : _stepQuantum; _stepQuantumCounter = xEntity.Attribute("StepQuantumCounter") != null? int.Parse(xEntity.Attribute("StepQuantumCounter").Value) : _stepQuantumCounter; XElement xDirection = xEntity.Element("MoveDirection"); if (xDirection != null) { _moveDirection.Up = (bool)xDirection.Attribute("Up"); _moveDirection.Down = (bool)xDirection.Attribute("Down"); _moveDirection.Left = (bool)xDirection.Attribute("Left"); _moveDirection.Right = (bool)xDirection.Attribute("Right"); } if (xEntity.Attribute("ImageURI") != null) { Image.Source = new BitmapImage(new Uri(xEntity.Attribute("ImageURI").Value)); } }
private void InitMovePace() { if (_movePattern == MovePattern.FollowingPlayer) { _movePace = MovePace.Constant; return; } int maxMovePaceValue = (int)Enum.GetValues(typeof(MovePace)).Cast <MovePace>().Max(); int movePaceValue = Utils.GetRandom(maxMovePaceValue + 1); if (Enum.IsDefined(typeof(MovePace), movePaceValue)) { _movePace = (MovePace)movePaceValue; if (_movePace == MovePace.Quantum) { _stepQuantum = Utils.GetRandom(DEFAULT_STEP_QUANTUM / 2, DEFAULT_STEP_QUANTUM + 1); } } }