Esempio n. 1
0
        public static ConsoleMario.Utility.Path LoadPathFromFile(int level_number)
        {
            ConsoleMario.Utility.Path path;
            string filename = pathstring + "path" + level_number;
            // Read the preview
            string previewfile = filename + ".preview";
            string pathpreview = "";

            try
            {
                List <string> loadedpreview = ReadLines(previewfile, true);
                for (int i = 0; i < loadedpreview.Count; i++)
                {
                    pathpreview += loadedpreview[i];
                }
            }
            catch (FileNotFoundException) { };
            // Read ExamplePath
            string examplefile = filename + ".example";

            ConsoleMario.Utility.Path example = null;
            try
            {
                example         = ReadPath(examplefile, level_number, true);
                example.Preview = pathpreview;
            }
            catch (FileNotFoundException) { }
            // Read Path
            string pathfile = filename + ".path";

            path = new Utility.Path(false, ReadPath(pathfile, level_number, false), example, pathpreview);
            return(path);
        }
Esempio n. 2
0
        private static ConsoleMario.Utility.Path ReadPath(string filename, int level, bool example)
        {
            ConsoleMario.Utility.Path path = null;
            // Read Path
            List <string> loadeddevices    = ReadLines(filename);
            string        fileparams       = filename + ".params";
            List <string> loadedparameters = null;

            try
            {
                loadedparameters = ReadLines(fileparams);
            }
            catch (FileNotFoundException) { }
            Device[,] devices = new Device[loadeddevices.Count, loadeddevices[0].ToCharArray().Length];
            int parameterindex = 0;

            for (int i = 0; i < devices.GetLength(0); i++)
            {
                // rows
                char[] rowdevices = loadeddevices[i].ToCharArray();
                // column
                for (int j = 0; j < rowdevices.Length; j++)
                {
                    if (devices[i, j] == null)
                    {
                        Device device = null;
                        if (rowdevices[j] != Key.KeyCharacter &&
                            rowdevices[j] != Spiral.SpiralCharacter)
                        {
                            device = Device.GetDeviceByCharacter(rowdevices[j]);
                        }
                        else
                        {
                            switch (rowdevices[j])
                            {
                            case Spiral.SpiralCharacter:
                                device = Device.GetDeviceByCharacter(rowdevices[j], ref parameterindex, loadedparameters[parameterindex]);
                                break;

                            case Key.KeyCharacter:
                                // Door's row, columns separated by
                                string[] positions = loadedparameters[parameterindex].Split(' ');
                                int      row       = Convert.ToInt32(positions[0]);
                                int      col       = Convert.ToInt32(positions[1]);
                                devices[row - 1, col - 1] = new Door();
                                device = Device.GetDeviceByCharacter(rowdevices[j], ref parameterindex, devices[row - 1, col - 1]);
                                break;
                            }
                        }
                        devices[i, j] = device;
                    }
                }
            }
            path = new Utility.Path(example, devices, level);
            return(path);
        }
 public FilesystemLocation(Path path) {
     _path = path;
 }
 public FilesystemLocation(Path path)
 {
     _path = path;
 }
 public ILocation GetLocation(string path)
 {
     return(new FilesystemLocation(Path.ParsePath(path)));
 }
 public ILocation GetChildLocation(string relativePath)
 {
     return(new FilesystemLocation(Path.ParsePath(AbsolutePath + "\\" + relativePath)));
 }
 public IEnumerable <ILocation> GetFiles(bool recurse)
 {
     if (!IsFileContainer)
     {
         return(Enumerable.Empty <ILocation>());
     }
     return(_path.FilePath.DirectoryEnumerateFilesSmarter(recurse ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly).Where(File.Exists).Select(each => new FilesystemLocation(Path.ParsePath(each))));
 }