Esempio n. 1
0
        private static BreedingPair ParseBreedingPair(string[][] data)
        {
            if (data.Length < 2 || data[0].Length == 0 || data[1].Length == 0)
            {
                throw new InputException("Breeding pair must start with both parents");
            }
            BreedingPair pair = new BreedingPair(GetFlower(data[0][0]), GetFlower(data[1][0]));

            if (data.Length < 3)
            {
                throw new InputException("Breeding pair must list one or more results");
            }
            for (var k = 2; k < data.Length; k++)
            {
                string[] item = data[k];
                if (item.Length < 1)
                {
                    throw new InputException("Breeding result must specify result flower ID");
                }
                if (item.Length < 2)
                {
                    throw new InputException("Breeding result must specify result chance in percentage");
                }
                pair.AddBreedingResult(GetFlower(item[0]), int.Parse(item[1]));
            }
            return(pair);
        }
Esempio n. 2
0
        private static void ParseBreedingPairSection(string[][][] data)
        {
            List <BreedingPair> pairs    = new List <BreedingPair>();
            BreedingPair        lastPair = null;

            if (data[0][0].Length == 0)
            {
                throw new InputException("Breeding pair section must start with target flower");
            }
            string[] targets = data[0][0];
            if (data[0].Length < 2 || data[0][1].Length == 0)
            {
                throw new InputException("Breeding pair section must specify background color");
            }
            string background = data[0][1][0];
            string border     = null;

            if (data[0][1].Length > 1)
            {
                border = data[0][1][1];
            }
            if (data.Length < 2)
            {
                throw new InputException("Breeding pair section must list breeding pairs");
            }
            for (int k = 1; k < data.Length; k++)
            {
                string[][] line = data[k];
                if (line[0].Length == 0)
                {
                    throw new InputException("Breeding pair must start with both parents");
                }
                if (line[0][0] == "-")
                {
                    lastPair.AddBreedingTest(ParseBreedingTest(line));
                }
                else if (line[0][0] == "!")
                {
                    if (line[0].Length < 2)
                    {
                        throw new InputException("Please specify impossible flower");
                    }
                    lastPair = new BreedingPair(GetFlower(line[0][1]));
                    pairs.Add(lastPair);
                }
                else
                {
                    lastPair = ParseBreedingPair(line);
                    pairs.Add(lastPair);
                }
            }
            breedingPairs.Add(new BreedingPairSection(pairs, targets, background, border));
        }