コード例 #1
0
ファイル: LoadPath.cs プロジェクト: cimbi01/ConsoleMario
        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);
        }
コード例 #2
0
ファイル: LoadPath.cs プロジェクト: cimbi01/ConsoleMario
        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);
        }
コード例 #3
0
 public FilesystemLocation(Path path) {
     _path = path;
 }
コード例 #4
0
 public FilesystemLocation(Path path)
 {
     _path = path;
 }
コード例 #5
0
 public ILocation GetLocation(string path)
 {
     return(new FilesystemLocation(Path.ParsePath(path)));
 }
コード例 #6
0
 public ILocation GetChildLocation(string relativePath)
 {
     return(new FilesystemLocation(Path.ParsePath(AbsolutePath + "\\" + relativePath)));
 }
コード例 #7
0
 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))));
 }