Esempio n. 1
0
        private void generateBoard()
        {
            generator.init();
            GenerateBoardResponse response = generator.generateTiles(this, boardEntitySelector.TileSelectionManager);

            this.coordinateToTile = response.coordinateToTile;
            this.tupleToWall      = response.tuppleToWall;
            RecalculateRemoveableTiles();
        }
Esempio n. 2
0
        public GenerateBoardResponse generateTiles(TileManager tileManager, TileSelectionManager pathSelectManager)
        {
            GenerateBoardResponse response = new GenerateBoardResponse();

            string[] mapItems = map.Split(NEWLINE);

            int y = 0;

            foreach (string line in mapItems)
            {
                bool   horizontal = line.Contains(WALL_V + "");
                char[] chars      = line.ToCharArray();
                for (int index = 0; index < chars.Length; index++)
                {
                    char c = chars[index];
                    int  x = index;
                    if (c == TILE_NORMAL)
                    {
                        Position   newPosition = new Position(x, y);
                        GameObject newTile     = Instantiate(tile);
                        newTile.transform.position = transform.position + (x * right) + (y * up);
                        newTile.GetComponent <Tile>().Init(newPosition, tileManager);
                        newTile.GetComponentInChildren <OutlineOnHover>().Init(pathSelectManager);
                        newTile.GetComponentInChildren <PathOnClick>().Init(pathSelectManager);
                        response.coordinateToTile.Add(newPosition, newTile.GetComponent <Tile>());

                        newTile.transform.SetParent(Board.transform);
                    }
                    if (c == WALL)
                    {
                        GameObject newTile = Instantiate(wall);
                        newTile.transform.position = transform.position + (x * right) + (y * up);
                        //newTile.GetComponent<Tile>().Init(newPosition, tileManager);
                        //newTile.GetComponentInChildren<OutlineOnHover>().Init(pathSelectManager);
                        //newTile.GetComponentInChildren<PathOnClick>().Init(pathSelectManager);
                        //response.coordinateToTile.Add(newPosition, newTile.GetComponent<Tile>());

                        newTile.transform.SetParent(Board.transform);
                    }
                    if (c == WALL_H)
                    {
                        Position   pos1    = new Position(x, y);
                        Position   pos2    = new Position(x + 1, y);
                        GameObject newWall = Instantiate(wallH);
                        newWall.transform.position = transform.position + (x * right) + (y * up) + (.5f * right);
                        response.tuppleToWall.Add(new Tuple <Position, Position>(pos1, pos2), newWall);

                        newWall.transform.parent = Board.transform;
                    }
                    if (c == WALL_V)
                    {
                        Position   pos1    = new Position(x, y);
                        Position   pos2    = new Position(x, y + 1);
                        GameObject newWall = Instantiate(wallH);
                        newWall.transform.position = transform.position + (x * right) + (y * up) + (.5f * up);
                        newWall.transform.Rotate(new Vector3(0, 0, 1), 90);
                        response.tuppleToWall.Add(new Tuple <Position, Position>(pos1, pos2), newWall);

                        newWall.transform.SetParent(Board.transform);
                    }
                }
                if (!horizontal)
                {
                    y++;
                }
            }
            return(response);
        }