/// <summary>
        /// Load a room from a file
        /// </summary>
        /// <param name="sourceFile">path of the file to use</param>
        public static void loadFromFile(string sourceFile, ReplacementRuleList templates)
        {
            Logger.Info($"Reading Replacement Rule in file {sourceFile}");
            Logger.Push();
            try
            {
                int          format = 0;
                StreamReader reader = new StreamReader(sourceFile);
                Int32.TryParse(reader.ReadLine(), out format);
                switch (format)
                {
                case 1:
                    Read_FileFormat_1(reader, templates);
                    break;

                default:
                    break;
                }
            }
            catch (Exception e)
            {
                Logger.Error(e.Message);
                Console.WriteLine(e.Message);
            }
            Logger.Pop();
        }
        /// <summary>
        /// Load all template files in the given directory

        /// </summary>
        /// <param name="sourceDirectory"> the directpry where to search for templates</param>
        /// <return> a list of all the templ    ate </return>
        public static ReplacementRuleList loadFromDirectory(String sourceDirectory, string name)
        {
            ReplacementRuleList templates = new ReplacementRuleList(name);

            loadFromDirectory(sourceDirectory, templates);
            return(templates);
        }
Beispiel #3
0
        public MapGenerator1(MapTemplateList rooms, MapTemplateList doors, ReplacementRuleList modifications)
        {
            Logger.Info($"Creating a map generator ", Logger.LogAction.PUSH);
            Logger.Info($"with {rooms.Count()} rooms");
            Logger.Info($"with {doors.Count()} type of doors");
            Logger.Info($"with {modifications.collection.Count} possible replacement");

            _rooms         = rooms;
            _doors         = doors;
            _modifications = modifications;
            Debug          = true;
            // put rooms into collections grouped by door type
            InitializeRooms();
            Logger.Pop();
        }
        /// <summary>
        /// Read a room in the "0" FileFormat
        /// First line is XSize
        ///Second Line is YSize
        ///Third line are operation to generate Mirror rooms (Rotate : X, H Mirror : X, V Mirror : Y)
        ///Followed by YSize lines of XSize chars
        /// </summary>
        /// <param name="reader"></param>
        public static void Read_FileFormat_1(StreamReader reader, ReplacementRuleList templates)
        {
            try
            {
                int priority = 1;
                int xsize    = 0;
                int ysize    = 0;
                int chance   = 100;
                Int32.TryParse(reader.ReadLine(), out priority);
                Int32.TryParse(reader.ReadLine(), out xsize);
                Int32.TryParse(reader.ReadLine(), out ysize);
                string operations = reader.ReadLine();

                char[,] initialData = loadData(reader, xsize, ysize);
                Int32.TryParse(reader.ReadLine(), out chance);
                char[,] replacementData = loadData(reader, xsize, ysize);

                // if requested, create mirrored copies
                List <char[, ]> initialMirrors =
                    CharUtils.CreateMirrors(initialData, operations);
                List <char[, ]> replacementMirrors =
                    CharUtils.CreateMirrors(replacementData, operations);
                for (int i = 0; i < initialMirrors.Count; i++)
                {
                    MapTemplate     initial     = new MapTemplate(initialMirrors[i]);
                    MapTemplate     replacement = new MapTemplate(replacementMirrors[i]);
                    ReplacementRule replace     = new ReplacementRule();
                    replace.InitialContent     = initial;
                    replace.ReplacementContent = replacement;
                    replace.Priority           = priority;
                    replace.Chance             = chance;
                    if (replace.Check())
                    {
                        templates.Add(replace);
                    }
                }
            }
            catch (Exception e)
            {
                Logger.Error(e.Message);
                Console.WriteLine(e.Message);
            }
        }
        /// <summary>
        /// Load all template files in the given directory and put them in the given list

        /// </summary>
        /// <param name="sourceDirectory"> the directpry where to search for templates</param>
        /// <param name="templates"> The liust of template to add the templates to</param>
        public static void loadFromDirectory(string sourceDirectory, ReplacementRuleList templates)
        {
            try
            {
                Logger.Info($"Reading Replacement Rules in directory {sourceDirectory} into {templates._name}");
                Logger.Push();
                var txtFiles =
                    Directory.EnumerateFiles(sourceDirectory, "*.rm2");
                foreach (string currentFile in txtFiles)
                {
                    loadFromFile(currentFile, templates);
                }
            }
            catch (Exception e)
            {
                Logger.Error(e.Message);
                Console.WriteLine(e.Message);
            }
            Logger.Pop();
        }
Beispiel #6
0
        static void Main(string[] args)
        {
            Logger.initialisation();
            // get char groups
            CharGroupsLoader.loadFromDirectory("./assets/");
            // get the rooms & doors template
            MapTemplateList rooms = MapTemplateLoader.loadFromDirectory("./assets/rooms", "rooms");
            // get the rooms & doors template
            MapTemplateList doors = MapTemplateLoader.loadFromDirectory("./assets/doors", "doors");
            // get the cleaning template rules
            ReplacementRuleList modifications = ReplacementRuleLoader.loadFromDirectory("./assets/modifications", "modifications");

            // create the map
            Map map = new Map(75, 75);
            // create the generator & call it
            MapGenerator1 generator = new MapGenerator1(rooms, doors, modifications);

            generator.GenerateMap(map);



            CharUtils.saveAsImage("./assets/map.png", map.Content);
        }