public void Init()
 {
     _baseLayer     = MapLayers[0];
     MapConstructor = new MapConstructor(MapLayers);
     MapDatas       = MapConstructor.GenerateMap();
     PathFinder     = new PathFinder(MapDatas);
     OutlinePool    = new OutlinePool(transform);
     _isInited      = true;
 }
    public override void OnInspectorGUI()
    {
        MapConstructor _target = (MapConstructor)target;

        serializedObject.Update();

        DrawDefaultInspector();

        GUI.backgroundColor = new Color(0.85f, 1f, 1f, 1);
        if (GUILayout.Button("Generate map"))
        {
            _target.GenerateNewMap();
        }
    }
Exemple #3
0
 public static Map Level1()
 {
     var map = new MapConstructor(20, 15);
     map=map
         .Descriptions("Ширина этой карты - {0} элементов, высота - {1}", null, map.Map.Width, map.Map.Height)
         .Frame();
     map.Map.Solution = wnd =>
         {
             for (int x = 0; x < 20 - 2 - 1; x++) wnd.Go(Directions.Right);
             for (int x = 0; x < 15 - 2 - 1; x++) wnd.Go(Directions.Down);
         };
     map.Map[18, 13] = new Door();
     return map.Map;
 }
Exemple #4
0
        public static Map Level10()
        {
            var map = new MapConstructor(18, 13);
            map=map
                .Descriptions("И наконец, общий случай", "Size {0} {1}", map.Map.Width,map.Map.Height)
                .Fill<Brick>()
                ;
            for (int i = 0; i < 5; i++)
                map = map.Dig(Directions.Right, 3).Dig(Directions.Down, 2);

            map.Map.Solution = wnd =>
                {
                    for (int i = 0; i <5; i++)
                    {
                        for (int j = 0; j < 3; j++) wnd.Go(Directions.Right);
                        for (int j = 0; j < 2; j++) wnd.Go(Directions.Down);
                    }
                };
            map.DoorHere();
            return map.Map;
        }
 public static void ScriptReferences()     //Assigns script references
 {
     systemListConstructor = GameObject.FindGameObjectWithTag("ScriptContainer").GetComponent <SystemListConstructor>();
     cameraFunctionsScript = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <CameraFunctions>();
     turnInfoScript        = GameObject.FindGameObjectWithTag("ScriptContainer").GetComponent <TurnInfo>();
     playerTurnScript      = GameObject.FindGameObjectWithTag("ScriptContainer").GetComponent <PlayerTurn>();
     diplomacyScript       = GameObject.FindGameObjectWithTag("ScriptContainer").GetComponent <DiplomacyControlScript>();
     systemGUI             = GameObject.FindGameObjectWithTag("GUIContainer").GetComponent <SystemGUI>();
     heroGUI               = GameObject.FindGameObjectWithTag("GUIContainer").GetComponent <HeroGUI>();
     racialTraitScript     = GameObject.FindGameObjectWithTag("ScriptContainer").GetComponent <RacialTraits> ();
     galaxyGUI             = GameObject.FindGameObjectWithTag("GUIContainer").GetComponent <GalaxyGUI>();
     invasionGUI           = GameObject.FindGameObjectWithTag("GUIContainer").GetComponent <InvasionGUI> ();
     mapConstructor        = GameObject.FindGameObjectWithTag("ScriptContainer").GetComponent <MapConstructor> ();
     winConditions         = GameObject.FindGameObjectWithTag("ScriptContainer").GetComponent <WinConditions> ();
     systemFunctions       = GameObject.FindGameObjectWithTag("ScriptContainer").GetComponent <SystemFunctions> ();
     systemInvasion        = GameObject.FindGameObjectWithTag("ScriptContainer").GetComponent <SystemInvasions> ();
     uiObjects             = GameObject.FindGameObjectWithTag("GUIContainer").GetComponent <UIObjects> ();
     ambientStarRandomiser = GameObject.FindGameObjectWithTag("ScriptContainer").GetComponent <AmbientStarRandomiser> ();
     voronoiGenerator      = GameObject.FindGameObjectWithTag("GUIContainer").GetComponent <VoronoiGeneratorAndDelaunay> ();
     heroResource          = GameObject.FindGameObjectWithTag("GUIContainer").GetComponent <HeroResourceImprovement> ();
     systemPopup           = GameObject.FindGameObjectWithTag("GUIContainer").GetComponent <SystemInfoPopup> ();
     triangulation         = GameObject.FindGameObjectWithTag("GUIContainer").GetComponent <Triangulation> ();
 }
Exemple #6
0
        public static Map Level11()
        {
            var map = new MapConstructor(21,16);
            map = map
                .Descriptions("Найдите общее решение для произвольного лабиринта такой формы", "Size {0} {1}", map.Map.Width, map.Map.Height)
                .Fill<Brick>()
                .Dig(Directions.Right, 18)
                .Dig(Directions.Down, 13)
                .Dig(Directions.Left, 18)
                .Dig(Directions.Up, 11)
                .Dig(Directions.Right, 16)
                .Dig(Directions.Down, 9)
                .Dig(Directions.Left, 14)
                .Dig(Directions.Up, 7)
                .Dig(Directions.Right, 12)
                .Dig(Directions.Down, 5)
                .Dig(Directions.Left, 10)
                .Dig(Directions.Up, 3)
                .Dig(Directions.Right, 8)
                .Dig(Directions.Down, 1)
                .DoorHere();

            return map.Map;
        }
Exemple #7
0
        public static Map Level9()
        {
            var map = new MapConstructor(6, 12);
            map = map
                 .Descriptions("А так?", "Size {0} {1}", map.Map.Width, map.Map.Height)
                 .Fill<Brick>()
                ;

            for (int i = 0; i < 3; i++)
                map = map.Dig(Directions.Right, 1).Dig(Directions.Down, 3);

            map.Map.Solution = wnd =>
            {
                for (int i = 0; i < 3; i++)
                {
                    for (int j = 0; j < 1; j++) wnd.Go(Directions.Right);
                    for (int j = 0; j < 3; j++) wnd.Go(Directions.Down);
                }
            };
            map.DoorHere();
            return map.Map;
        }
Exemple #8
0
        public static Map Level7()
        {
            var map = new MapConstructor(15, 6);
            map = map
                 .Descriptions("Далее мы будем проходить лабиринты со ступеньками. Траектория всегда одинаковая: влево-вниз-влево-вниз", "Size {0} {1}", map.Map.Width, map.Map.Height)
                 .Fill<Brick>()
                ;

            for (int i = 0; i < 3; i++)
                map = map.Dig(Directions.Right, 4).Dig(Directions.Down, 1);

            map.Map.Solution = wnd =>
            {
                for (int i = 0; i < 3; i++)
                {
                    for (int j = 0; j < 4; j++) wnd.Go(Directions.Right);
                    for (int j = 0; j < 1; j++) wnd.Go(Directions.Down);
                }
            };
            map.DoorHere();
            return map.Map;
        }
Exemple #9
0
 public static Map Level6()
 {
     var map = new MapConstructor(13, 11)
         .Descriptions("А если так?", "Levels 10 -2 -2 -5")
         .Fill<Brick>()
         .Dig(Directions.Right, 10)
         .Dig(Directions.Down, 2)
         .Dig(Directions.Left, 2)
         .Dig(Directions.Down, 2)
         .Dig(Directions.Left, 2)
         .Dig(Directions.Down, 2)
         .Dig(Directions.Left, 5)
         .Dig(Directions.Down, 2)
         .DoorHere();
     return map.Map;
 }
Exemple #10
0
 public static Map Level5()
 {
     var map = new MapConstructor(22, 11)
         .Descriptions("Как элегантно решить эту задачу с помощью foreach и массивов? Размеры этажей: 5, 2, 7, 5", "Levels 5 2 7 5")
         .Fill<Brick>()
         .Dig(Directions.Right, 5)
         .Dig(Directions.Down, 2)
         .Dig(Directions.Right, 2)
         .Dig(Directions.Down, 2)
         .Dig(Directions.Right, 7)
         .Dig(Directions.Down, 2)
         .Dig(Directions.Right, 5)
         .Dig(Directions.Down, 2)
         .DoorHere();
     return map.Map;
 }
Exemple #11
0
 public static Map Level3()
 {
     var map = new MapConstructor(16, 15);
     map = map
          .Descriptions("Сделайте общий алгоритм для прохождения змейки. Размеры лабиринта возьмите из переменной MapInfo", "Size {0} {1}", map.Map.Width, map.Map.Height)
          .Fill<Brick>();
     for (int i = 0; i < 3; i++)
         map.Dig(Directions.Right, 13).Dig(Directions.Down, 2).Dig(Directions.Left, 13).Dig(Directions.Down, 2);
     map.DoorHere();
     return map.Map;
 }
Exemple #12
0
 public static Map Level2()
 {
     var map = new MapConstructor(20, 11);
     map = map
          .Descriptions("Ширина - {0}, высота - {1}", "Size {0} {1}", map.Map.Width, map.Map.Height)
          .Fill<Brick>();
     for (int i = 0; i < 2; i++)
         map.Dig(Directions.Right, 17).Dig(Directions.Down, 2).Dig(Directions.Left, 17).Dig(Directions.Down, 2);
     map.DoorHere();
     return map.Map;
 }
Exemple #13
0
        public static Map Level14()
        {
            var data=new []
            {
                "  x     x   xxxx      xx      x    ",
                "   x   x    x   x    x  x    xxx   ",
                "    x x     x   x   x    x   xxx   ",
                "     x      xxxx    xxxxxx    x    ",
                "    x       x       x    x         ",
                "   x        x       x    x    x    "
            };

            var map = new MapConstructor(data[0].Length,data.Length).Descriptions("Вы прошли все уровни",null).Map;

            for (int x=0;x<map.Width;x++)
                for (int y=0;y<map.Height;y++)
                    map[x,y]=data[y][x]==' '?null:new Brick();
            map[1, 1] = new Player();
            return map;
        }
Exemple #14
0
 public static Map Level0()
 {
     var map = new MapConstructor(10, 3).Descriptions("Просто идите в направлении Right!", null).Frame();
     map.Map[8, 1] = new Door();
     return map.Map;
 }
Exemple #15
0
        public static Map Level13()
        {
            var data = new[] {
                "                              ",
                " XXXXXXXXXXXXXXXXXX XXXXXXX X ",
                "  X   X      X    X X       X ",
                "  X X X XXXX XXXX X X X XXX X ",
                "  X XXX X X  X    X X X X   X ",
                "  X     X X  X XXXX XXX XXXXX ",
                " XXXXXXXX X       X X X X X X ",
                "          X  X XXXXXX XXX X X ",
                "  XXXXXXXXX  X            X X ",
                "  X     X    XXXXXXXXXXXXXX X ",
                "  X XXXXX                 X X ",
                "  X   X X   XXXXXXXXXXXX  X X ",
                "  X   X X           X  XXXX X ",
                "  X       X                 X  ",
                "  XXXXXXXXXXXXXXXXXXXXXXXXX X ",
                "                              ",
            };
            var map = new MapConstructor(data[0].Length, data.Length).Descriptions("А теперь выберетесь из настоящего лабиринта. Это просто - нужно всегда поворачивать в одну и ту же сторону...", null).Map;

            for (int x = 0; x < map.Width; x++)
                for (int y = 0; y < map.Height; y++)
                    map[x, y] = data[y][x] == ' ' ? new Wood() : null;
            map[1, 1] = map.Player;
            map[map.Width - 2, map.Height - 2] = new Door();
            return map;
        }
Exemple #16
0
        /// <summary>
        /// Constructs a new engine instance and allows customizing options.
        /// </summary>
        /// <remarks>The provided engine instance in callback is not guaranteed to be fully configured</remarks>
        public Engine(Action <Engine, Options> options)
        {
            _executionContexts = new ExecutionContextStack(2);

            Global = GlobalObject.CreateGlobalObject(this);

            Object   = ObjectConstructor.CreateObjectConstructor(this);
            Function = FunctionConstructor.CreateFunctionConstructor(this);
            _callerCalleeArgumentsThrowerConfigurable    = new GetSetPropertyDescriptor.ThrowerPropertyDescriptor(this, PropertyFlag.Configurable | PropertyFlag.CustomJsValue, "'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them");
            _callerCalleeArgumentsThrowerNonConfigurable = new GetSetPropertyDescriptor.ThrowerPropertyDescriptor(this, PropertyFlag.CustomJsValue, "'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them");

            Symbol   = SymbolConstructor.CreateSymbolConstructor(this);
            Array    = ArrayConstructor.CreateArrayConstructor(this);
            Map      = MapConstructor.CreateMapConstructor(this);
            Set      = SetConstructor.CreateSetConstructor(this);
            Iterator = IteratorConstructor.CreateIteratorConstructor(this);
            String   = StringConstructor.CreateStringConstructor(this);
            RegExp   = RegExpConstructor.CreateRegExpConstructor(this);
            Number   = NumberConstructor.CreateNumberConstructor(this);
            Boolean  = BooleanConstructor.CreateBooleanConstructor(this);
            Date     = DateConstructor.CreateDateConstructor(this);
            Math     = MathInstance.CreateMathObject(this);
            Json     = JsonInstance.CreateJsonObject(this);
            Proxy    = ProxyConstructor.CreateProxyConstructor(this);
            Reflect  = ReflectInstance.CreateReflectObject(this);

            GlobalSymbolRegistry = new GlobalSymbolRegistry();

            // Because the properties might need some of the built-in object
            // their configuration is delayed to a later step

            // trigger initialization
            Global.GetProperty(JsString.Empty);

            // this is implementation dependent, and only to pass some unit tests
            Global._prototype = Object.PrototypeObject;
            Object._prototype = Function.PrototypeObject;

            // create the global environment http://www.ecma-international.org/ecma-262/5.1/#sec-10.2.3
            GlobalEnvironment = LexicalEnvironment.NewGlobalEnvironment(this, Global);

            // create the global execution context http://www.ecma-international.org/ecma-262/5.1/#sec-10.4.1.1
            EnterExecutionContext(GlobalEnvironment, GlobalEnvironment);

            Eval = new EvalFunctionInstance(this);
            Global.SetProperty(CommonProperties.Eval, new PropertyDescriptor(Eval, PropertyFlag.Configurable | PropertyFlag.Writable));

            Options = new Options();

            options?.Invoke(this, Options);

            // gather some options as fields for faster checks
            _isDebugMode       = Options.IsDebugMode;
            _isStrict          = Options.IsStrict;
            _constraints       = Options._Constraints;
            _referenceResolver = Options.ReferenceResolver;

            _referencePool         = new ReferencePool();
            _argumentsInstancePool = new ArgumentsInstancePool(this);
            _jsValueArrayPool      = new JsValueArrayPool();

            if (Options._IsClrAllowed)
            {
                Global.SetProperty("System", new PropertyDescriptor(new NamespaceReference(this, "System"), PropertyFlag.AllForbidden));
                Global.SetProperty("importNamespace", new PropertyDescriptor(new ClrFunctionInstance(
                                                                                 this,
                                                                                 "importNamespace",
                                                                                 (thisObj, arguments) => new NamespaceReference(this, TypeConverter.ToString(arguments.At(0)))), PropertyFlag.AllForbidden));
            }

            ClrTypeConverter = new DefaultTypeConverter(this);
        }
Exemple #17
0
        public static Map Level12()
        {
            var map = new MapConstructor(18, 14)
                .Descriptions("В деревянные стены безопасно врезаться. Метод Go возвращает false, если перемещение сделать не получилось. В этом лабиринте надо поворачивать направо, упершись в стену", null)
                .Fill<Wood>()
                .Dig(Directions.Right, 5)
                .Dig(Directions.Down, 7)
                .Dig(Directions.Left, 3)
                .Dig(Directions.Up, 3)
                .Dig(Directions.Right, 7)
                .Dig(Directions.Down, 7)
                .Dig(Directions.Left, 9)
                .Dig(Directions.Up,9)
                .Dig(Directions.Right,15)
                .Dig(Directions.Down, 9)
                .Dig(Directions.Left,4)
                .Dig(Directions.Up,11)
                .Dig(Directions.Right,2)
                .Dig(Directions.Down,9)
                .DoorHere();

            return map.Map;
        }
Exemple #18
0
 public static Map Level4()
 {
     var map = new MapConstructor(21, 11);
     map = map
          .Descriptions("Как пройти этот уровень с минимальными усилиями? Размер поля {0} на {1}", null, map.Map.Width, map.Map.Height)
          .Fill<Brick>()
          .Dig(Directions.Right, 1);
     for (int i = 0; i < 2; i++)
         map.Dig(Directions.Right, 17).Dig(Directions.Down, 2).Dig(Directions.Left, 17).Dig(Directions.Down, 2);
     map.DoorHere();
     return map.Map;
 }
Exemple #19
0
        public Engine(Action <Options> options)
        {
            _executionContexts = new ExecutionContextStack();

            Global = GlobalObject.CreateGlobalObject(this);

            Object   = ObjectConstructor.CreateObjectConstructor(this);
            Function = FunctionConstructor.CreateFunctionConstructor(this);

            Symbol   = SymbolConstructor.CreateSymbolConstructor(this);
            Array    = ArrayConstructor.CreateArrayConstructor(this);
            Map      = MapConstructor.CreateMapConstructor(this);
            Set      = SetConstructor.CreateSetConstructor(this);
            Iterator = IteratorConstructor.CreateIteratorConstructor(this);
            String   = StringConstructor.CreateStringConstructor(this);
            RegExp   = RegExpConstructor.CreateRegExpConstructor(this);
            Number   = NumberConstructor.CreateNumberConstructor(this);
            Boolean  = BooleanConstructor.CreateBooleanConstructor(this);
            //            Date = DateConstructor.CreateDateConstructor(this);
            Math = MathInstance.CreateMathObject(this);
            Json = JsonInstance.CreateJsonObject(this);

            Error          = ErrorConstructor.CreateErrorConstructor(this, "Error");
            EvalError      = ErrorConstructor.CreateErrorConstructor(this, "EvalError");
            RangeError     = ErrorConstructor.CreateErrorConstructor(this, "RangeError");
            ReferenceError = ErrorConstructor.CreateErrorConstructor(this, "ReferenceError");
            SyntaxError    = ErrorConstructor.CreateErrorConstructor(this, "SyntaxError");
            TypeError      = ErrorConstructor.CreateErrorConstructor(this, "TypeError");
            UriError       = ErrorConstructor.CreateErrorConstructor(this, "URIError");

            GlobalSymbolRegistry = new GlobalSymbolRegistry();

            // Because the properties might need some of the built-in object
            // their configuration is delayed to a later step

            Global.Configure();

            Object.Configure();
            Object.PrototypeObject.Configure();

            Symbol.Configure();
            Symbol.PrototypeObject.Configure();

            Function.Configure();
            Function.PrototypeObject.Configure();

            Array.Configure();
            Array.PrototypeObject.Configure();

            Map.Configure();
            Map.PrototypeObject.Configure();

            Set.Configure();
            Set.PrototypeObject.Configure();

            Iterator.Configure();
            Iterator.PrototypeObject.Configure();

            String.Configure();
            String.PrototypeObject.Configure();

            RegExp.Configure();
            RegExp.PrototypeObject.Configure();

            Number.Configure();
            Number.PrototypeObject.Configure();

            Boolean.Configure();
            Boolean.PrototypeObject.Configure();

            //            Date.Configure();
            //            Date.PrototypeObject.Configure();

            Math.Configure();
            Json.Configure();

            Error.Configure();
            Error.PrototypeObject.Configure();

            // create the global environment http://www.ecma-international.org/ecma-262/5.1/#sec-10.2.3
            GlobalEnvironment = LexicalEnvironment.NewObjectEnvironment(this, Global, null, false);

            // create the global execution context http://www.ecma-international.org/ecma-262/5.1/#sec-10.4.1.1
            EnterExecutionContext(GlobalEnvironment, GlobalEnvironment, Global);

            Options = new Options();

            options?.Invoke(Options);

            // gather some options as fields for faster checks
            _isDebugMode = Options.IsDebugMode;

            if (_isDebugMode)
            {
                MyAPIGateway.Utilities.ShowMessage("SpaceJS", "Debug mode enabled.");
            }

            _isStrict                 = Options.IsStrict;
            _maxStatements            = Options._MaxStatements;
            _referenceResolver        = Options.ReferenceResolver;
            _memoryLimit              = Options._MemoryLimit;
            _runBeforeStatementChecks = (_maxStatements > 0 && _maxStatements < int.MaxValue) ||
                                        Options._TimeoutInterval.Ticks > 0 ||
                                        _memoryLimit > 0 ||
                                        _isDebugMode;

            _referencePool         = new ReferencePool();
            _argumentsInstancePool = new ArgumentsInstancePool(this);
            _jsValueArrayPool      = new JsValueArrayPool();

            Eval = new EvalFunctionInstance(this, System.ArrayExt.Empty <string>(), LexicalEnvironment.NewDeclarativeEnvironment(this, ExecutionContext.LexicalEnvironment), StrictModeScope.IsStrictModeCode);
            Global.FastAddProperty("eval", Eval, true, false, true);

            _statements  = new StatementInterpreter(this);
            _expressions = new ExpressionInterpreter(this);

            /*            if (Options._IsClrAllowed)
             *          {
             *              Global.FastAddProperty("System", new NamespaceReference(this, "System"), false, false, false);
             *              Global.FastAddProperty("importNamespace", new ClrFunctionInstance(
             *                  this,
             *                  "importNamespace",
             *                  (thisObj, arguments) => new NamespaceReference(this, TypeConverter.ToString(arguments.At(0)))), false, false, false);
             *          }
             */
            //            ClrTypeConverter = new DefaultTypeConverter(this);
        }
    void Awake()
    {
        Map = new List <Tile> ();
        var map = new HashSet <Hex> ();

        switch (Shape)
        {
        case MapShapes.Triangle:
            map = MapConstructor.TriangleMap(Width);
            break;

        case MapShapes.ReverseTrianlge:
            map = MapConstructor.ReverseTriangleMap(Width);
            break;

        case MapShapes.Rectangular:
            map = MapConstructor.RectangularlMap(Width, Height);
            break;

        case MapShapes.Hexagonal:
            map = MapConstructor.HexagonalMap(Width);
            break;
        }

        var obstacles = new List <Hex> ()
        {
            // new Hex(1, 0 ,-1), new Hex(1,1,-2), new Hex(0,3,-3), new Hex(1,4,-5),
            //  new Hex(2,2,-4), new Hex(3,1,-4), new Hex(0,2,-2)
        };

        foreach (var hex in map)
        {
            var prefab = GameObject.Instantiate(Prefab, hex, Quaternion.identity);
            prefab.name = hex.ToString();
            var tile = prefab.GetComponent <Tile> ();

            if (tile == null)
            {
                continue;
            }

            var isEven = Type == MapType.PointyOdd || Type == MapType.FlatOdd || Shape != MapShapes.Rectangular;
            if (Type == MapType.FlatEven || Type == MapType.FlatOdd)
            {
                tile.InitFlat(hex, isEven);
            }
            else
            {
                tile.InitPointy(hex, isEven);
            }
            Map.Add(tile);
            prefab.transform.SetParent(transform);

            if (hex == new Hex(-1, 2, -1))
            {
                Origin = tile;
            }

            if (!obstacles.Contains(hex))
            {
                continue;
            }
            prefab.GetComponent <Renderer> ().material.SetColor("_Color", Color.green);
            prefab.transform.localScale = new Vector3(1, 1, 0.3f);
            var z = (1 - prefab.transform.localScale.z) * 0.125f;
            prefab.transform.position += new Vector3(0, 0, z);
            tile.isObstacle            = true;
        }

        Map.ForEach((T) => T.GetNeighbors());
        transform.rotation = Quaternion.Euler(90, 0, 0);
        DoneShowing        = true;
    }