Exemplo n.º 1
0
        /// <summary>
        /// Считывание из XML врагов.
        /// </summary>
        /// <param name="parXmlReader">Парсер XML в нужном состоянии.</param>
        /// <returns>Список созданных врагов.</returns>
        private static List <EnemyObject> ParseEnemies(XmlReader parXmlReader)
        {
            List <EnemyObject> enemies = new List <EnemyObject>();

            parXmlReader.ReadToFollowing("enemies");
            parXmlReader.Read();
            while (parXmlReader.ReadToNextSibling("enemy"))
            {
                EnemyObject enemy = new EnemyObject();
                parXmlReader.ReadToDescendant("type");
                enemy.Type = (EnemyObjectType)Enum.Parse(typeof(EnemyObjectType), parXmlReader.ReadElementContentAsString());
                parXmlReader.ReadToNextSibling("damage");
                enemy.Damage = parXmlReader.ReadElementContentAsInt();
                parXmlReader.ReadToNextSibling("x");
                enemy.X = parXmlReader.ReadElementContentAsFloat();
                parXmlReader.ReadToNextSibling("y");
                enemy.Y = parXmlReader.ReadElementContentAsFloat();
                parXmlReader.ReadToNextSibling("sizeX");
                enemy.SizeX = parXmlReader.ReadElementContentAsFloat();
                parXmlReader.ReadToNextSibling("sizeY");
                enemy.SizeY = parXmlReader.ReadElementContentAsFloat();
                parXmlReader.ReadToNextSibling("state");
                enemy.State = parXmlReader.ReadElementContentAsInt();
                parXmlReader.ReadToNextSibling("flippedY");
                enemy.FlippedY = parXmlReader.ReadElementContentAsBoolean();
                parXmlReader.ReadToNextSibling("isMoving");
                enemy.IsMoving = parXmlReader.ReadElementContentAsBoolean();
                if (parXmlReader.ReadToNextSibling("leftWalkingBoundX"))
                {
                    enemy.LeftWalkingBoundX = parXmlReader.ReadElementContentAsFloat();
                    parXmlReader.ReadToNextSibling("leftWalkingBoundY");
                    enemy.LeftWalkingBoundY = parXmlReader.ReadElementContentAsFloat();
                    parXmlReader.ReadToNextSibling("rightWalkingBoundX");
                    enemy.RightWalkingBoundX = parXmlReader.ReadElementContentAsFloat();
                    parXmlReader.ReadToNextSibling("rightWalkingBoundY");
                    enemy.RightWalkingBoundY = parXmlReader.ReadElementContentAsFloat();
                    parXmlReader.ReadEndElement();
                }
                else
                {
                    enemy.LeftWalkingBoundX  = 0;
                    enemy.LeftWalkingBoundY  = 0;
                    enemy.RightWalkingBoundX = 0;
                    enemy.RightWalkingBoundY = 0;
                    parXmlReader.ReadEndElement();
                }

                enemies.Add(enemy);
            }

            return(enemies);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Инициализирует логику объекта.
 /// </summary>
 /// <param name="parLevel">Уровень.</param>
 /// <param name="parEnemy">Объект.</param>
 public GhostLogic(GameModel parLevel, EnemyObject parEnemy) : base(parLevel)
 {
     Enemy = parEnemy;
 }