Esempio n. 1
0
        public string Get()
        {
            var cityGenerator = new CityGenerator();

            if (!cityGenerator.Generate())
            {
                return("Error");
            }

            var factoryGenerator = new FactoryGenerator();

            if (!factoryGenerator.Generate())
            {
                return("Error");
            }

            var utilityGenerator = new UtilityGenerator();

            if (!utilityGenerator.Generate())
            {
                return("Error");
            }

            var regionGenerator = new RegionGenerator();

            if (!regionGenerator.Generate())
            {
                return("Error");
            }

            var containerGenerator = new ContainerGenerator();

            if (!containerGenerator.Generate())
            {
                return("Error");
            }

            var tripGenerator = new TripGenerator();

            if (!tripGenerator.Generate())
            {
                return("Error");
            }

            return("Success");
        }
Esempio n. 2
0
 public void Generate(int Seed, int Level, int Regions)
 {
     transform.ClearChildrenImmediately();
     if (engine == null)
     {
         Load();
     }
     {
         System.Random    random = new System.Random(Seed);
         List <BlockId[]> map    = new List <BlockId[]>();
         int height = 0;
         List <RegionGenerator> validGenerators = new List <RegionGenerator>();
         //<Generate Start>
         var start_unit = new BlockId[] { BlockId.Solid };
         for (int i = 0; i < 20; i++)
         {
             map.Add(start_unit);
         }
         //<End>
         for (int region_id = 0; region_id < Regions; region_id++)
         {
             try
             {
                 int   seed = random.Next();
                 float max  = 0;
                 foreach (RegionGenerator function in functions)
                 {
                     if (function.CanAttach(height))
                     {
                         validGenerators.Add(function);
                         function.Init(seed);
                         max += function.Probability(Level);
                     }
                 }
                 if (validGenerators.Count == 0)
                 {
                     break;
                 }
                 float           point = (float)random.NextDouble() * max;
                 RegionGenerator f     = null;
                 foreach (RegionGenerator function in validGenerators)
                 {
                     point -= function.Probability(Level);
                     if (point <= 0)
                     {
                         f = function;
                         break;
                     }
                 }
                 validGenerators.Clear();
                 PythonTuple output = f.Generate(Level, height);
                 List        region = (List)output[0];
                 height = (int)output[1];
                 List <BlockId> l = new List <BlockId>();
                 foreach (List column in region)
                 {
                     foreach (int obj in column)
                     {
                         l.Add((BlockId)obj);
                     }
                     map.Add(l.ToArray());
                     l.Clear();
                 }
             }
             catch { }
         }
         //<Generate End>
         BlockId[] end_unit    = new BlockId[height + 1];
         BlockId[] finish_unit = new BlockId[height + 4];
         for (int i = 0; i < height; i++)
         {
             end_unit[i]    = BlockId.Space;
             finish_unit[i] = BlockId.Space;
         }
         end_unit[height]        = BlockId.Solid;
         finish_unit[height]     = BlockId.Solid;
         finish_unit[height + 1] = BlockId.Space;
         finish_unit[height + 2] = BlockId.Space;
         finish_unit[height + 3] = BlockId.Finish;
         for (int i = 0; i < 30; i++)
         {
             if (i == 15)
             {
                 map.Add(finish_unit);
             }
             else
             {
                 map.Add(end_unit);
             }
         }
         //<End>
         Map = map.ToArray();
         Write(Map);
     }
     OnGenerated.Invoke();
 }