Exemple #1
0
        static void Main(string[] args)
        {
            List <Street> streets = null;

            try
            {
                streets = Serializations.XMLDeserialize <List <Street> >(path, new Type[] { typeof(List <Street>) });
            }
            catch (IOException ioex)
            {
                Console.WriteLine(ioex.Message);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            var magicHouses = (from str in streets
                               where - str && ~str % 2 != 0
                               select str).ToArray();

            if (magicHouses.Length == 0)
            {
                Console.WriteLine("Волшебных домов не обнаружено");
            }
            else
            {
                foreach (var str in magicHouses)
                {
                    Console.WriteLine(str);
                }
            }
        }
    public void SetPlayerInventory(List <ShipEquipment> newInventory)
    {
        List <int> playerInventoryEquipmentsIndexes = new List <int>();

        foreach (ShipEquipment equip in newInventory)
        {
            playerInventoryEquipmentsIndexes.Add(equip.GetEquipmentSaveIndex);
        }

        playerInventoryEquipments = Serializations.SerializeListOfInt(playerInventoryEquipmentsIndexes);
    }
    public void SetPlayerEquipmentsData(EquipmentsSet equipedEquipments, List <ShipEquipment> inventoryEquipments, int armorAmount, int goldAmount)
    {
        PlayerInventory playerInventory = new PlayerInventory(inventoryEquipments);

        #region Set
        List <int> playerEquipedEquipmentsIndexes = new List <int>();
        if (equipedEquipments.GetHullEquipment != null)
        {
            playerEquipedEquipmentsIndexes.Add(equipedEquipments.GetHullEquipment.GetEquipmentSaveIndex);
        }
        else
        {
            playerEquipedEquipmentsIndexes.Add(-1);
        }

        if (equipedEquipments.GetMainWeaponEquipment != null)
        {
            playerEquipedEquipmentsIndexes.Add(equipedEquipments.GetMainWeaponEquipment.GetEquipmentSaveIndex);
        }
        else
        {
            playerEquipedEquipmentsIndexes.Add(-1);
        }

        if (equipedEquipments.GetSecondaryWeaponEquipment != null)
        {
            playerEquipedEquipmentsIndexes.Add(equipedEquipments.GetSecondaryWeaponEquipment.GetEquipmentSaveIndex);
        }
        else
        {
            playerEquipedEquipmentsIndexes.Add(-1);
        }

        playerEquipedEquipments = Serializations.SerializeListOfInt(playerEquipedEquipmentsIndexes);
        #endregion

        #region Inventory
        List <int> playerInventoryEquipmentsIndexes = new List <int>();

        foreach (ShipEquipment equip in inventoryEquipments)
        {
            playerInventoryEquipmentsIndexes.Add(equip.GetEquipmentSaveIndex);
        }

        playerInventoryEquipments = Serializations.SerializeListOfInt(playerInventoryEquipmentsIndexes);
        #endregion

        playerArmorAmout = armorAmount;

        playerGoldAmount = goldAmount;
    }
        static void Main(string[] args)
        {
            int           N       = GetNumber <int>("Введите количество улиц", x => x > 0);
            List <Street> streets = new List <Street>();

            if (CheckStreetFile(path_in))
            {
                string[] streetsData = File.ReadAllLines(path_in, Encoding.GetEncoding("Windows-1251"));
                foreach (var street in streetsData)
                {
                    string[] str    = street.Split(new char[] { ' ' });
                    int      number = -1;
                    var      nums   = (from t in str
                                       where int.TryParse(t, out number)
                                       select number).ToList();
                    try
                    {
                        streets.Add(new Street(str[0], nums.ToArray()));
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                        return;
                    }
                }
            }
            else
            {
                FillStreetData(streets, N);
            }
            while (N < streets.Count)
            {
                streets.RemoveAt(streets.Count - 1);
            }
            foreach (var street in streets)
            {
                Console.WriteLine(street);
            }
            Serializations.XMLSerialize(streets, path_out, new Type[] { typeof(List <Street>) });
        }