Ejemplo n.º 1
0
        public MazeViewModel(MazeSettings settings)
        {
            _Settings            = settings;
            _Constructor         = new MazeConstructor(settings);
            _CellsViewModelsList = GetCellsViewModelsList();

            Content = GetMazeVisualization();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 部屋オブジェクトを作成
        /// </summary>
        /// <param name="roomViewList"></param>
        /// <param name="mazeSettings"></param>
        private void MakeRoomView(ref Dictionary <int, RoomView> roomViewList, MazeSettings mazeSettings)
        {
            // RoomViewの生成
            var indexed = _maze.Rooms.WithIndex().Where(x => x.Element.IsEnable).Shuffle().ToList();

            foreach (var room in indexed)
            {
                var coordinate = new Vector3(room.Element.Coordinate.X + Interval * room.Element.Coordinate.X, 0, -(room.Element.Coordinate.Y + Interval) * room.Element.Coordinate.Y);

                GameObject go;

                switch (room.Element.RoomAttribute)
                {
                case Room.RoomAttributes.FloorStart:
                {
                    go = _container.InstantiatePrefab(mazeSettings.PlayerRoom, coordinate, Quaternion.identity,
                                                      null);
//						go = Object.Instantiate(_mazeSettings.PlayerRoom, coordinate, Quaternion.identity);
                    break;
                }

                case Room.RoomAttributes.Stair:
                {
//						go = _container.InstantiatePrefab(mazeSettings.EnemyRoom, coordinate, Quaternion.identity, null);
                    go = _container.InstantiatePrefab(mazeSettings.EnemyRoom.RandomAt(), coordinate, Quaternion.identity,
                                                      null);
                    _container.InstantiateComponent <SpawnStairComponent>(go);

//						go = Object.Instantiate(_mazeSettings.EnemyRoom, coordinate, Quaternion.identity);
                    // 階段コンポーネントを追加
//						go.AddComponent<SpawnStairComponent>();
                    break;
                }

                case Room.RoomAttributes.Others:
                {
                    go = _container.InstantiatePrefab(mazeSettings.EnemyRoom.RandomAt(), coordinate, Quaternion.identity,
                                                      null);
                    // go = Object.Instantiate(_mazeSettings.EnemyRoom, coordinate, Quaternion.identity);
                    break;
                }

                default:
                    throw new ArgumentOutOfRangeException();
                }

                var goTransform  = go.transform;
                var cameraAnchor = Object.Instantiate(mazeSettings.BirdsEyeCamera, goTransform);

                var view = go.GetComponent <RoomView>();
                view.Construct(room.Element, cameraAnchor.transform);
                roomViewList.Add(room.Element.Id, view);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 迷宮を実体化する
        /// </summary>
        /// <returns></returns>
        public MazeView Construct(MazeSettings mazeSettings)
        {
            var rooms  = new Dictionary <int, RoomView>();
            var aisles = new Dictionary <int, AisleView>();

            MakeRoomView(ref rooms, mazeSettings);
//			MakeAisleView(ref aisles, rooms);

            var mazeView = MazeView.Create(_maze, rooms, aisles);

            return(mazeView);
        }
Ejemplo n.º 4
0
        private MazeSettings GetMazeSettings(Maze maze)
        {
            var settings = new MazeSettings();

            settings.XPos         = Width / 2;
            settings.YPos         = Height / 2;
            settings.WindowHeight = Height;
            settings.WindowWidth  = Width;
            settings.Maze         = maze;

            return(settings);
        }
Ejemplo n.º 5
0
 public static MazeGrid GenerateMazeGrid(MazeSettings settings)
 {
     if (settings.useDistanceGrid)
     {
         return(new DistanceMazeGrid(settings.gridWidth, settings.gridHeight));
     }
     else
     {
         return(new MazeGrid(settings.gridWidth, settings.gridHeight));
     }
     ///return new MazeGrid(settings.gridWidth, settings.gridHeight);
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Maze生成
        /// </summary>
        public void Construct(MazeSettings mazeSettings)
        {
            var maze = ConstructMaze();
            var view = ConstructMazeView(maze, mazeSettings);

            _mazeView = view;

            _mazeView.Initialize();

            var entryPoint = maze.GetEntryPoint();
            var startRoom  = view.Rooms[entryPoint.Id];

            _transportSystem.Initialize(startRoom);

            _isReady = true;

            Log("Constructed.");
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 迷宮を実体化する
        /// </summary>
        /// <param name="maze"></param>
        /// <param name="mazeSettings"></param>
        /// <returns></returns>
        private MazeView ConstructMazeView(Maze.Maze maze, MazeSettings mazeSettings)
        {
            var viewBuilder = _mazeViewBuilderFactory.Create(maze);

            return(viewBuilder.Construct(mazeSettings));
        }
Ejemplo n.º 8
0
 public MazeTextLoader(MazeSettings mazeSettings, ILogger <MazeTextLoader> logger)
 {
     _mazeSettings = mazeSettings;
     _logger       = logger;
 }
Ejemplo n.º 9
0
        public void GenerateMazePrefab(string nameMaze)
        {
            MazeJSONData mazeJSONData;
            bool         tryLoadMaze = MazeJSONTool.LoadMazeJSON(nameMaze, out mazeJSONData);

            if (tryLoadMaze)
            {
                GameObject obj = new GameObject(nameMaze);
                obj.layer = LayerMask.NameToLayer("Game");
                MazeBase maze = obj.AddComponent <MazeBase>();

                // Maze settings
                MazeSettings mazeSettings = new MazeSettings(mazeJSONData.Columns, mazeJSONData.Rows);
                mazeSettings.NameMaze = nameMaze;
                //mazeSettings.StartPoint = mazeJSONData.StartLocation;
                //mazeSettings.EndPoint = mazeJSONData.EndLocation;

                maze.InitializeMaze(mazeSettings);

                // Create rooms
                Debug.Log("number rooms: " + mazeJSONData.NumberRooms);
                maze.CreateRooms(mazeJSONData.NumberRooms);

                // Create cells
                Debug.Log("number tiles: " + mazeJSONData.ListTiles.Count);
                for (int i = 0; i < mazeJSONData.ListTiles.Count; i++)
                {
                    IVector2 coordsCell = new IVector2(mazeJSONData.ListTiles[i].Coords.Column, mazeJSONData.ListTiles[i].Coords.Row);

                    // Instance cell
                    GameObject goCell = Instantiate(m_CellPrefab);
                    goCell.layer            = LayerMask.NameToLayer("Game");
                    goCell.name             = "Cell_" + coordsCell.Column + "_" + coordsCell.Row;
                    goCell.transform.parent = obj.transform;
                    // Set position tiles
                    goCell.transform.localPosition = new Vector3(coordsCell.Column * m_TileSize, 0.0f, coordsCell.Row * m_TileSize);
                    // Setup index room
                    MazeCell mCell = goCell.GetComponent <MazeCell>();
                    mCell.Coords = coordsCell;

                    // Set type cell
                    mCell.SetTypeCell(mazeJSONData.ListTiles[i].TileType);
                    if (mazeJSONData.ListTiles[i].TileType == MazeCell.ETypeCell.STARTLOCATION)
                    {
                        mazeSettings.StartPoint = coordsCell;
                    }
                    if (mazeJSONData.ListTiles[i].TileType == MazeCell.ETypeCell.ENDLOCATION)
                    {
                        mazeSettings.EndPoint = coordsCell;
                    }



                    /*bool bVisibleTile = true;
                     * if (mazeJSONData.ListTiles[i].IsVisible == 0)
                     * {
                     *  bVisibleTile = false;
                     * }
                     * if (mCell.IsVisible)
                     * {
                     *
                     *  // Set material for start point
                     *  if ((coordsCell.Column == mazeSettings.StartPoint.Column) && (coordsCell.Row == mazeSettings.StartPoint.Row))
                     *  {
                     *      mCell.SetTypeCell(MazeCell.ETypeCell.STARTLOCATION);
                     *  }
                     *
                     *  // Set material for start point
                     *  else if ((coordsCell.Column == mazeSettings.EndPoint.Column) && (coordsCell.Row == mazeSettings.EndPoint.Row))
                     *  {
                     *      mCell.SetTypeCell(MazeCell.ETypeCell.ENDLOCATION);
                     *
                     *  }
                     *  else
                     *  {
                     *      // Check if the coords are in the list of holes
                     *      bool isHole = false;
                     *      for (int iHole = 0; iHole < mazeJSONData.ListHoles.Count; iHole++)
                     *      {
                     *          if ((coordsCell.Column == mazeJSONData.ListHoles[iHole].Coords.Column) && (coordsCell.Row == mazeJSONData.ListHoles[iHole].Coords.Row))
                     *          {
                     *              mCell.SetTypeCell(MazeCell.ETypeCell.HOLE);
                     *              isHole = true;
                     *
                     *              Debug.LogFormat("HOLE DATA: Coords {0}x{1} TypeHole: {2} ConnectedCoords: {3}x{4} ", mazeJSONData.ListHoles[iHole].Coords.Column, mazeJSONData.ListHoles[iHole].Coords.Row, mazeJSONData.ListHoles[iHole].TypeHole, mazeJSONData.ListHoles[iHole].ConnectedCoords.Column, mazeJSONData.ListHoles[iHole].ConnectedCoords.Row);
                     *
                     *              mazeSettings.AddHole(mazeJSONData.ListHoles[iHole]);
                     *              mCell.SetHole(mazeJSONData.ListHoles[iHole]);
                     *              break;
                     *          }
                     *      }
                     *
                     *      if (!isHole)
                     *      {
                     *          mCell.SetTypeCell(MazeCell.ETypeCell.NONE);
                     *      }
                     *  }
                     *
                     *  // Add obstacles
                     *  for (int iObstacle = 0; iObstacle < mazeJSONData.ListObstacles.Count; iObstacle++)
                     *  {
                     *      if ((mCell.Coords.Column == mazeJSONData.ListObstacles[iObstacle].Coords.Column) && (mCell.Coords.Row == mazeJSONData.ListObstacles[iObstacle].Coords.Row))
                     *      {
                     *          // Instance obstacle
                     *          mCell.SetObstacle(mazeJSONData.ListObstacles[iObstacle]);
                     *          break;
                     *      }
                     *  }
                     *
                     * }*/
                    // Add cell to the maze
                    maze.AddCell(mCell);
                }
                // Segup each edge for each cells
                for (int i = 0; i < mazeJSONData.ListTiles.Count; i++)
                {
                    MazeCell currentCell = maze.GetCell(mazeJSONData.ListTiles[i].Coords);

                    if (currentCell.TypeCell != MazeCell.ETypeCell.INVISIBLE)
                    {
                        // Setup each cell
                        for (int iEdge = 0; iEdge < mazeJSONData.ListTiles[i].Edges.Length; iEdge++)
                        {
                            // Gets connected cell with this edge
                            // Gets direction for this edge
                            MazeDirection dir = (MazeDirection)iEdge;

                            IVector2 coordsConnectedCell = mazeJSONData.ListTiles[i].Coords + dir.ToIntVector2();

                            // Get connected cell (it could be null)
                            MazeCell connectedCell = maze.GetCell(coordsConnectedCell);

                            // Get type edge
                            MazeCellEdge.TypeEdgeEnum tEdge = mazeJSONData.ListTiles[i].Edges[iEdge];

                            currentCell.SetEdge(dir, tEdge, connectedCell);
                        }
                    }
                }

#if UNITY_EDITOR
                // Create prefab
                string fileLocation = "Assets/TheMaze/Prefabs/Mazes/" + nameMaze + ".prefab";
                Object emptyObj     = PrefabUtility.CreateEmptyPrefab(fileLocation);

                PrefabUtility.ReplacePrefab(obj, emptyObj, ReplacePrefabOptions.ConnectToPrefab);
#endif
            }
        }