Beyond_Beyaan.Data_Modules.AI.Initialize C# (CSharp) Метод

Initialize() публичный Метод

public Initialize ( FileInfo file ) : bool
file System.IO.FileInfo
Результат bool
        public bool Initialize(FileInfo file)
        {
            List<string> errors = new List<string>();
            string[] lines;

            try
            {
                lines = File.ReadAllLines(file.FullName);
            }
            catch (Exception e)
            {
                errors.Add("Exception occured: " + e.Message);
                return false;
            }

            foreach (string line in lines)
            {
                if (string.IsNullOrEmpty(line) || line.StartsWith("//"))
                {
                    continue;
                }
                string[] parts = line.Split(new[] { '|' });
                if (parts.Length == 2)
                {
                    if (string.Compare(parts[0], "name", true) == 0)
                    {
                        AIName = parts[1];
                        continue;
                    }
                }
                else
                {
                    errors.Add("\"" + line + "\" is not a valid line.  Must have two values, separated by |");
                    break;
                }
            }

            return errors.Count == 0;
        }

Usage Example

Пример #1
0
 public bool Initialize(DirectoryInfo directory, out string reason)
 {
     try
     {
         DirectoryInfo di = new DirectoryInfo(Path.Combine(directory.FullName, "ai"));
         if (!di.Exists)
         {
             //If it don't exist, create one so users can add races
             di.Create();
         }
         foreach (FileInfo fi in di.GetFiles("*.txt"))
         {
             AI ai = new AI();
             if (ai.Initialize(fi))
             {
                 AIs.Add(ai);
             }
         }
         reason = null;
         return true;
     }
     catch (Exception e)
     {
         reason = e.Message;
         return false;
     }
 }