Ejemplo n.º 1
0
            internal static Level TryGetTemplateLevel(string text)
            {
                if (text == null)
                {
                    throw new SettingsException("The level template is null.");
                }

                if (File.Exists(text))
                {
                    try
                    {
                        var template = Level.FromPath(text);
                        template.Path = null;
                        return(template);
                    }
                    catch (Exception)
                    {
                        throw new SettingsException("The level template file is not a valid Elma level file.");
                    }
                }

                var regex = new Regex(@"^(\d+),(\d+)$");

                if (!regex.IsMatch(text))
                {
                    throw new SettingsException(
                              "The level template is neither a file nor a string of the form \"width,height\".");
                }

                double width  = int.Parse(regex.Match(text).Groups[1].Value);
                double height = int.Parse(regex.Match(text).Groups[2].Value);

                return(Level.FromDimensions(width, height));
            }
Ejemplo n.º 2
0
 internal Level GetTemplateLevel()
 {
     try
     {
         return(TryGetTemplateLevel(LevelTemplate));
     }
     catch (SettingsException)
     {
         return(Level.FromDimensions(50, 50));
     }
 }