Beispiel #1
0
        private ShipCreator()
        {
            _ship = new Ship();
            Builder = new Dictionary<ShipNum, ShipInfo>();

            var shipRecords = new List<ShipInfo>();
            var serializer = new XmlSerializer(shipRecords.GetType());
            using (var reader = XmlReader.Create("shipConfig.xml"))
            {
                shipRecords = (List<ShipInfo>)serializer.Deserialize(reader);
                foreach (var shipRecord in shipRecords)
                {
                    var num = new ShipNum { Index = shipRecord.Index, Race = shipRecord.Race };
                    Builder[num] = shipRecord;
                }
            }
        }
Beispiel #2
0
 public void BuildShip(Ship ship, Point coord)
 {
     MapCells[coord.X, coord.Y].Ship = ship;
 }
Beispiel #3
0
        private bool Shoot(Ship attacker, Ship target, Point coord, bool isAtkMine, List<AttackInfo> log)
        {
            var isDestroyed = false;
            var myDmg = Random.Next(attacker.MinDamage, attacker.MaxDamage);
            target.Health -= myDmg;
            if (target.Health <= 0)
            {
                MapCells[coord.X, coord.Y].Ship = null;
                isDestroyed = true;
            }

            var record = new AttackInfo { Damage = myDmg, IsDestroyed = isDestroyed, IsMineAttack = isAtkMine };

            if (attacker.Abilities != null)
                foreach (var skill in attacker.Abilities)
                {
                    switch (skill)
                    {
                        case AbilityName.Corrosion:
                            record.Debuff = AbilityName.Corrosion;
                            target.Status.Add(new ActiveEffect
                            {
                                Name = EffectName.Corrosion,
                                TurnsLeft = 5
                            });
                            break;
                    }
                }

            log.Add(record);
            return isDestroyed;
        }
Beispiel #4
0
 private AbilityResult PerformAbility(AbilityName ability, Ship invokator)
 {
     var coords = GetShipCoordinates(invokator);
     return _abilities[ability].Perform(this, coords);
 }
Beispiel #5
0
 private Point GetShipCoordinates(Ship ship)
 {
     for (var j = 0; j < Consts.MAP_HEIGHT; j++)
     {
         for (var i = 0; i < Consts.MAP_WIDTH; i++)
         {
             if (MapCells[i, j].Ship == ship)
                 return new Point(i, j);
         }
     }
     return new Point(-1, -1);
 }
Beispiel #6
0
 public Point GetShipPosition(Ship s)
 {
     for (var j = 0; j < MapCells.GetLength(1); j++)
         for (var i = 0; i < MapCells.GetLength(0); i++)
             if (MapCells[i,j].Ship == s)
                 return new Point(i,j);
     return new Point(-1, -1);
 }