public void Initialize(Vector2Int size, GameTileContentFactory contentFactory) { ClearBoard(); this.size = size; ground.localScale = new Vector3(size.x, size.y, 1f); Vector2 offset = new Vector2( (size.x - 1) * 0.5f, (size.y - 1) * 0.5f ); tiles = new GameTile[size.x * size.y]; for (int i = 0, y = 0; y < size.y; y++) { for (int x = 0; x < size.x; x++, i++) { GameTile tile = tiles[i] = Instantiate(tilePrefab); tile.transform.SetParent(transform, false); tile.transform.localPosition = new Vector3( x - offset.x, 0f, y - offset.y ); tile.Content = contentFactory.Get(GameTileContentType.Empty); } } }
public void Initialize(Vector2Int size, GameTileContentFactory contentFactory) { this.size = size; this.contentFactory = contentFactory; ground.localScale = new Vector3(size.x, size.y, 1f); Vector2 offset = new Vector2((size.x - 1) * 0.5f, (size.y - 1) * 0.5f); tiles = new GameaTile[size.x * size.y]; for (int i = 0, y = 0; y < size.y; y++) { for (int x = 0; x < size.x; x++, i++) { GameaTile tile = tiles[i] = Instantiate(tilePrefab); tile.transform.SetParent(transform, false); tile.transform.localPosition = new Vector3(x - offset.x, 0f, y - offset.y); if (x > 0) { GameaTile.MakeEastWestNeighbors(tile, tiles[i - 1]); } if (y > 0) { GameaTile.MakeNorthSouthNeighbors(tile, tiles[i - size.x]); } tile.IsAlternative = (x & 1) == 0; if ((y & 1) == 0) { tile.IsAlternative = !tile.IsAlternative; } tile.Content = contentFactory.Get(GameTileContentType.Empty); } } //FindPaths(); ToggleDestination(tiles[tiles.Length / 2]); ToggleSpawnPoint(tiles[0]); }
public void Initialize(Vector2 size, GameTileContentFactory contentFactory) { //生成地板 this.size = size; this.contentFactory = contentFactory; ground.localScale = new Vector3(size.x, size.y, 1f); //创建箭头 tiles = new GameTile[(int)(size.x * size.y)]; //x轴偏移及y轴偏移 Vector2 offset = new Vector2( (size.x - 1) * 0.5f, (size.y - 1) * 0.5f ); //i:个数 x:行 y:列 for (int i = 0, y = 0; y < size.y; y++) { for (int x = 0; x < size.x; x++, i++) { GameTile tile = tiles[i] = Instantiate(titlePrefab); tile.gameObject.name = i.ToString(); tile.transform.SetParent(transform, false); //从左到右排列,以0为中心点 tile.transform.localPosition = new Vector3( x - offset.x, 0f, y - offset.y ); if (x > 0) { //构建行的左右关系 //Tip:从左到右读取 GameTile.MakeLeftRightNeighbors(tile, tiles[i - 1]); } //进入就可以表示已经有第二行了 if (y > 0) { //构建列的上下关系 //Tip:i - (int)size.x 当>0时,才表示有下一行,也才可确定当前该列的上下 GameTile.MakeUpBottomNeightbors(tile, tiles[i - (int)size.x]); } //都是把左右两边变成二进制,然后逐位进行运算 //1 & 1 = 1 1 & 0 = 0 0 & 1 = 0 0 & 0 = 0 //1 | 1 = 1 1 | 0 = 1 0 | 1 = 1 0 | 0 = 0 //偶数&1肯定为0 tile.IsAlternative = (x & 1) == 0; if ((y & 1) == 0) { //偶数行取反 tile.IsAlternative = !tile.IsAlternative; } //tile.Content = contentFactory.Get(GameTileContentType.Empty); } } // ToggleDestination(tiles[tiles.Length / 2]); // ToggleSpawnPoint(tiles[0]); Clear(); }
//initializes game board size and sets tiles public void Initialize(Vector2Int size, GameTileContentFactory contentFactory) { this.size = size; this.contentFactory = contentFactory; ground.localScale = new Vector3(size.x, size.y, 1f); Vector2 offset = new Vector2( (size.x - 1) * 0.5f, (size.y - 1) * 0.5f ); tiles = new GameTile[size.x * size.y]; //sets the tiles across the board for (int i = 0, y = 0; y < size.y; y++) { for (int x = 0; x < size.x; x++, i++) { GameTile tile = tiles[i] = Instantiate(tilePrefab); tile.transform.SetParent(transform, false); tile.transform.localPosition = new Vector3( x - offset.x, 0f, y - offset.y ); //helps set of neighbors if (x > 0) { GameTile.MakeEastWestNeighbors(tile, tiles[i - 1]); } if (y > 0) { GameTile.MakeNorthSouthNeighbors(tile, tiles[i - size.x]); } // X & 1 works as 'and' operator, this sets even number tiles as alt tiles tile.IsAlternative = (x & 1) == 0; //negates result if y coord is even if ((y & 1) == 0) { tile.IsAlternative = !tile.IsAlternative; } } } Clear(); }
//Methoden----------------------------- public void Initialize(Vector2Int size, GameTileContentFactory contentFactory) { this.size = size; this.contentFactory = contentFactory; ground.localScale = new Vector3(size.x, size.y, 1f); Vector2 offset = new Vector2( (size.x - 1) * 0.5f, (size.y - 1) * 0.5f); tiles = new GameTile[size.x * size.y]; for (int i = 0, y = 0; y < size.y; y++) { for (int x = 0; x < size.x; x++, i++) { GameTile tile = tiles[i] = Instantiate(tilePrefab); //erstellt sie und schreibt sie gleichzeitig in ein array, in einer zeile!!! tile.transform.SetParent(transform, false); tile.transform.localPosition = new Vector3(x - offset.x, 0f, y - offset.y); //Erstellt Nord Süd/ West Ost beziehungen if (x > 0) { GameTile.MakeEastWestNeighbors(tile, tiles[i - 1]); } if (y > 0) { GameTile.MakeNorthSouthNeighbors(tile, tiles[i - size.x]); } tile.IsAlternative = (x & 1) == 0; if ((y & 1) == 0) { tile.IsAlternative = !tile.IsAlternative; } tile.Content = contentFactory.Get(GameTileContentType.Empty); //Gibt jeder Kachel einen leeren Empty Inhalt } } //FindPaths(); //Aufruf der Pfad Methode ToggleDestination(tiles[tiles.Length / 2]); }
public void Initialize(Vector2Int size, GameTileContentFactory contentFactory) { // inicializa o mapa this.size = size; this.contentFactory = contentFactory; ground.localScale = new Vector3(size.x, size.y, 1f); tiles = new GameTile[size.x * size.y]; Vector2 offset = new Vector2( (size.x - 1) * 0.5f, (size.y - 1) * 0.5f ); for (int y = 0, i = 0; y < size.y; y++) { for (int x = 0; x < size.x; x++, i++) { GameTile tile = tiles[i] = Instantiate(tilePrefab); tile.transform.SetParent(transform, false); // define as posições tile.transform.localPosition = new Vector3( x - offset.x, 0f, y - offset.y ); if (x > 0) { GameTile.MakeEastWestNeighbors(tile, tiles[i - 1]); } if (y > 0) { GameTile.MakeNorthSouthNeighbors(tile, tiles[i - size.x]); } tile.isAlternative = (x & 1) == 0; // é par if ((y & 1) == 0) { tile.isAlternative = !tile.isAlternative; } // define o conteúdo } } Clear(); }
//--------------------------------------------------------- //Functions public void Initialize(Vector2Int size, GameTileContentFactory contentFactory) { //Board this.size = size; this.contentFactory = contentFactory; ground.localScale = new Vector3(size.x, size.y, 1f); //Tiles //Check if we have tiles if (tiles.Length != 0) { //The tiles are set but not their neighbour yet SetTilesNeighbours(); //We set the content to empty foreach (GameTile tile in tiles) { tile.Content = contentFactory.Get(GameTileContentType.Empty); } //We will get the original tiles info for (int i = 0, y = 0; y < size.y; y++) { for (int x = 0; x < size.x; x++, i++) { ContentTypeBeginToggleFunction(tiles[i]); tiles[i].IsAlternative = (x & 1) == 0; if ((y & 1) == 0) { tiles[i].IsAlternative = !tiles[i].IsAlternative; } //We add it to our collection //originalTile.Add(tile); } } } //If we don't have tiles, we will create them else { Vector2 offset = new Vector2((size.x - 1) * 0.5f, (size.y - 1) * 0.5f); tiles = new GameTile[size.x * size.y]; for (int i = 0, y = 0; y < size.y; y++) { for (int x = 0; x < size.x; x++, i++) { GameTile tile = tiles[i] = Instantiate(tilePrefab); tile.transform.SetParent(transform, false); tile.transform.localPosition = new Vector3(x - offset.x, 0f, y - offset.y); if (x > 0) { GameTile.MakeEastWestNeighbors(tile, tiles[i - 1]); } if (y > 0) { GameTile.MakeNorthSouthNeighbors(tile, tiles[i - size.x]); } //Set the alternative part of the tile (for having diagonal arrows) tile.IsAlternative = (x & 1) == 0; if ((y & 1) == 0) { tile.IsAlternative = !tile.IsAlternative; } //Set tile as empty tile.Content = contentFactory.Get(GameTileContentType.Empty); } } } Clear(); }