Ejemplo n.º 1
0
//``````````````````````````````````````````````````````````````````````````````````````````````````````````
//``````````````````````````````````````````````````````````````````````````````````````````````````````````
    void Start()
    {
        //creation of maze matrix at start
        var maze = MazeCreator.Create(height, width);

        Draw(maze);
    }
Ejemplo n.º 2
0
        public void Initialize(IGameSettingsManager gameSettingsManager, CinemachineVirtualCamera mainCamera)
        {
            _gameSettingsManager = gameSettingsManager;
            var gameConfig = _gameSettingsManager.GameConfig;

            _player      = Object.Instantiate(gameConfig.PlayerPrefab).GetComponent <IActor>();
            _mazeCreator = new MazeCreator(_gameSettingsManager.GameConfig);
            _player.Initialize(this);

            _mainCamera        = mainCamera;
            _mainCamera.Follow = _player.Transform;

            var fpvCamera = _player.Abilities.Find(ability => ability is AbilityFPV) as AbilityFPV;

            if (fpvCamera != null)
            {
                _fpvCamera = fpvCamera.FpvCamera;
            }

            if (_player == null || !gameConfig.MazeLevelsConfigList.Any())
            {
                return;
            }

            StartLevel(0);
        }
Ejemplo n.º 3
0
        private static void Run()
        {
            /*
             * int testTime = 4;
             * double allTime = 0f;
             * for (int i = 0; i < testTime; i++)
             * {
             *  // Test the algorithm
             *  Console.WriteLine("迷路生成中...");
             *  var map = MazeCreator.Create(51, 51, new Vec2(2, 2));
             *  Console.WriteLine("    生成完了.\n");
             *  var algorithm = new HeatingSearcher(map);
             *
             *  double elapsedMs1 = Timer.ElapsedMilliSec();
             *  algorithm.Solve();
             *  double elapsedMs2 = Timer.ElapsedMilliSec();
             *
             *  allTime += elapsedMs2 - elapsedMs1;
             * }
             * Console.WriteLine("Average Time: " + allTime / (double)testTime);*/


            var map = MazeCreator.Create(21, 21, new Vec2(2, 2));

            map.Dump();
            Console.WriteLine();
            double t1        = Timer.ElapsedMilliSec();
            var    algorithm = new Dijkstra(map);
            double t2        = Timer.ElapsedMilliSec();

            Console.WriteLine("Elapsed Time: " + (t2 - t1));
            //var searcher = new ParallelHeatingSearcher(map);
        }
 public void Command_Initialize_Maze_Large()
 {
     this.command = CommandCreator.CreateMazeCreatorCommand(this.player, "large");
     this.command.Execute();
     this.mazeFactory = (this.command as MazeCreateCommand).CreateMaze(this.renderer);
     this.player.Maze = this.mazeFactory.CreateMaze();
     Assert.AreEqual(this.player.Maze.Cols, 31);
     Assert.AreEqual(this.player.Maze.Rows, 31);
 }
    public void InitGame()
    {
        // First reset anything that already exists
        if (player)
        {
            player.goalAcheived = false;
        }
        if (startLevel != null)
        {
            Destroy(startLevel.gameObject);
            startLevel = null;
        }
        if (mainRune != null)
        {
            runes.Add(mainRune);
        }
        if (gameBoard != null)
        {
            for (int i = 0; i < gameBoard.GetLength(0); i++)
            {
                for (int j = 0; j < gameBoard.GetLength(1); j++)
                {
                    if (gameBoard[i, j] != null)
                    {
                        Destroy(gameBoard[i, j].gameObject);
                        gameBoard[i, j] = null;
                    }
                }
            }
        }

        if (player == null)
        {
            player = (Player)Instantiate(playerCharacter, Vector3.zero, Quaternion.Euler(0, -90, 0));
        }
        gameBoard = new GameSquare[size, size];
        maze      = new MazeCreator(size, 3, new int[] { startX, startY - 1 });
        Debug.Log("Start at " + maze.start[0].ToString() + " " + maze.start[1].ToString());
        Debug.Log("End at " + maze.end[0].ToString() + " " + maze.end[1].ToString());
        for (int i = 0; i < 10; i++)
        {
            string test = "";
            for (int j = 0; j < 10; j++)
            {
                test += maze.maze[j, i].ToString();
            }
            Debug.Log(test);
        }
        curX = startX;
        curY = startY;
        int runeIndex = Random.Range(0, runes.Count - 1);

        mainRune = runes[runeIndex];
        runes.RemoveAt(runeIndex);
        ActivateCurrentSquare();
        MovePlayerToSpawn(Directions.North);
    }
 public void Command_Initialize_Maze_Medium()
 {
     this.commander.SetCommand(CommandCreator.CreateMazeCreatorCommand(this.player, "medium"));
     this.commander.ExecuteCommand();
     this.mazeFactory = this.commander.GetMaze(this.renderer);
     this.player.Maze = this.mazeFactory.CreateMaze();
     Assert.AreEqual(this.player.Maze.Cols, 21);
     Assert.AreEqual(this.player.Maze.Rows, 21);
 }
Ejemplo n.º 7
0
    void Start()
    {
        Application.runInBackground = true;

        MazeCreator.CreateMaze(wall, floor, red, green);

        genotype_fitness = new List <GenotypeFitness>();

        NewRandomGeneration();
    }
Ejemplo n.º 8
0
    public MazePathFinder(MazeCreator creator, Action <Point> cellAction = null, Action finishAction = null)
    {
        this.cells = creator.cells;

        searchPoints4Bfs = new Queue <Point>();
        searchPoints4Dfs = new Stack <Point>();

        startPoint = creator.StartPoint;
        endPoint   = creator.EndPoint;

        CheckCells    = cellAction;
        FinishFinding = finishAction;
    }
Ejemplo n.º 9
0
    void Start()
    {
        ColorCells = new Color[Width, Height];

        creator = new MazeCreator(Width, Height, UseReferImage);

        CellImage = new Image[Width, Height];
        CellMarks = new Dictionary <Point, Image>();

        MazeInit();

        // 显示单元设置
        creator.SetLinkAct += ShowCell;
    }
Ejemplo n.º 10
0
    // Set room and key counters
    private void InitializeText()
    {
        // initialize key count and set key text
        keyCount = 0;
        SetKeyText();

        // find the total number of rooms and set room text
        GameObject  maze        = GameObject.Find("Maze Generator");
        MazeCreator mazeCreator = maze.transform.GetComponent <MazeCreator>();

        roomCount = mazeCreator.roomCount;

        SetRoomText();
    }
Ejemplo n.º 11
0
    private void GenerateMazePath()
    {
        List <Direction> cur      = ChoosePath();
        List <Direction> newpaths = MazeCreator.FindPath(mazeDim, mazeDim, cur[cur.Count - 1]);

        Debug.Log("Background maze path");
        if (choosePathA)
        {
            mazePathB = newpaths;
        }
        else
        {
            mazePathA = newpaths;
        }
    }
Ejemplo n.º 12
0
        public IMap CreateMaze(int cols, int rows, int maxTileIndex = 100)
        {
            MazeCreator creator = new MazeCreator(cols, rows, new System.Drawing.Point(1, 1));

            int[,] tiles = null;
            do
            {
                tiles = new MazeCreator(cols, rows, new System.Drawing.Point(1, 1)).CreateMaze();
            } while (tiles[2, 1] != 0);
            Vector2 playerPosition = new Vector2(1.5f, 1.5f);
            var     map            = new BaseMap()
            {
                PlayersInitialViewingDirection = 0, PlayerStartingPoint = playerPosition, Tiles = tiles
            };

            return(map);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Command pattern and maze initialization after valid maze choice
        /// <remarks>
        /// Choice must be between the allowed maze size enumerations
        /// </remarks>
        /// </summary>
        private IMaze InitMaze()
        {
            string labSizeChoice = string.Empty;

            this.Renderer.Render(WELCOME_MESSAGE);
            this.Renderer.Render(CHOOSE_LAB_MESAGE);

            while (this.mazeFactory == null)
            {
                // Command pattern...
                labSizeChoice = this.Renderer.ReadCommand().ToLower();
                this.commander.SetCommand(CommandCreator.CreateMazeCreatorCommand(this.Player, labSizeChoice));
                this.commander.ExecuteCommand();
                this.mazeFactory = this.commander.GetMaze(this.Renderer);
            }

            return(this.mazeFactory.CreateMaze());
        }
Ejemplo n.º 14
0
    public void SetupRamp(GameObject rampObject)
    {
        pathQueue = new CircularQueue <PathPrefab>(queueLength);
        buildPoint.transform.position = new Vector3(0, 0, 30);
        tearDownComplete = false;
        foreach (Transform child in rampObject.transform)
        {
            ramp = child.gameObject;
            ramp.GetComponent <BoxCollider>().enabled = false;
            pathQueue.Add(ramp.GetComponent <PathPrefab>());
        }

        lastDirection = Direction.North;
        lastPath      = ramp.GetComponent <PathPrefab>();

        mazePathA      = MazeCreator.FindPath(mazeDim, mazeDim, lastDirection);
        choosePathA    = true;
        mazePathIndex  = 0;
        mazePathBuffer = 10;
    }
Ejemplo n.º 15
0
        private async void EllerAsync(Cell[,] cells)
        {
            await Task.Run(() =>
            {
                MazeCreator mc = new MazeCreator((cells.GetUpperBound(1) + 1) / 2, (cells.GetUpperBound(0) + 1) / 2);
                mc.Generate();
                for (int i = 0; i < cells.GetUpperBound(0); i++)
                {
                    for (int j = 0; j < cells.GetUpperBound(1); j++)
                    {
                        if (cells[i, j].Blocked)
                        {
                            continue;
                        }
                        else
                        {
                            if (mc.Maze[i / 2][j / 2].Bottom && i >= 1)
                            {
                                cells[i + 1, j].Blocked = true;
                            }
                            if (mc.Maze[i / 2][j / 2].Right && j >= 1)
                            {
                                cells[i, j + 1].Blocked = true;
                            }
                            if (mc.Maze[i / 2][j / 2].Top && mc.Maze[i / 2][j / 2].Left && i >= 1 && j >= 1)
                            {
                                cells[i - 1, j - 1].Blocked = true;
                            }
                            if (mc.Maze[i / 2][j / 2].Bottom && mc.Maze[i / 2][j / 2].Right)
                            {
                                cells[i + 1, j + 1].Blocked = true;
                            }
                        }
                    }
                }
                _grid = new Grid(cells);
            });

            CreateGridImage(10);
        }
Ejemplo n.º 16
0
 public void Create(MazeCreator creator)
 {
     creator.Create(width, height, Field);
 }