Example #1
0
        public void ParseSkillsFromString(string skillSave)
        {
            match1 = first.Match(skillSave);
            int i = 1;
            while (match1.Success) {
                Console.WriteLine("Match" + (i + 1));
                if (match1.Groups[1].Value != "" && match1.Groups[1].Value != null) {
                    //Создание верменного массива и увеличение основного на одну ячеку
                    Array.Resize<Skill>(ref skillArr, i);

                    //Задание строковых переменных
                    string name = match1.Groups[1].Value;
                    string type = match1.Groups[3].Value;

                    bool avalible;

                    int maxLevel;

                    SkillData baseS = new SkillData();
                    SkillData perL = new SkillData();

                    //Первый блок try, в котором задаются такие переменные, как avalible, level и maxlevel
                    try {
                        int j = int.Parse(match1.Groups[2].Value);
                        if (j == 0)
                            avalible = false;
                        else
                            avalible = true;
                        maxLevel = int.Parse(match1.Groups[4].Value);
                    } catch (FormatException e) {
                        Console.WriteLine("Some errors while parsing data" + e.Message);
                        avalible = false;
                        maxLevel = 0;
                    }
                    //Начало второго цикла регулярных выражений
                    match2 = second.Match(match1.Groups[5].Value);
                    //Считывание значений перезарядки
                    try {
                        baseS.cd = double.Parse(match2.Groups[1].Value);
                        if (match2.Groups[2].Value == "+")
                            perL.cd = double.Parse(match2.Groups[3].Value);
                        else
                            perL.cd = double.Parse(match2.Groups[3].Value) * -1;
                    } catch (FormatException e) {
                        Console.WriteLine("Some errors while parsing data" + e.Message);
                    }
                    match2 = match2.NextMatch();
                    //Считывание значений стоимости умения
                    try {
                        baseS.cost = double.Parse(match2.Groups[1].Value);
                        if (match2.Groups[2].Value == "+")
                            perL.cost = double.Parse(match2.Groups[3].Value);
                        else
                            perL.cost = double.Parse(match2.Groups[3].Value) * -1;
                    } catch (FormatException e) {
                        Console.WriteLine("Some errors while parsing data" + e.Message);
                    }
                    match2 = match2.NextMatch();
                    //Считывание значений длительности
                    try {
                        baseS.duration = double.Parse(match2.Groups[1].Value);
                        if (match2.Groups[2].Value == "+")
                            perL.duration = double.Parse(match2.Groups[3].Value);
                        else
                            perL.duration = double.Parse(match2.Groups[3].Value) * -1;
                    } catch (FormatException e) {
                        Console.WriteLine("Some errors while parsing data" + e.Message);
                    }
                    //Конец считывания по второму регулярному выражению

                    //Задание ранее считанных параметров новому умению
                    skillArr[i - 1] = new Skill(name, avalible, type, maxLevel, baseS, perL);
                }
                i++;
                match1 = match1.NextMatch();
            }
        }
Example #2
0
 public void AddSkillToArray(Skill sk)
 {
     Array.Resize<Skill>(ref skillArr, skillArr.Length + 1);
     skillArr[skillArr.Length - 1] = sk;
 }