public void Initialize_Candy_And_Spawn_Positions_From_Premade_Level() { Initialise_Variables(); var premadeLevel = s_Debugging.Fill_Tiles_Array(); if (tiles != null) { Destroy_All_Tiles(); } tiles = new s_TileArray(); SpawnPositions = new Vector2[s_Constants.columns]; for (int row = 0; row < s_Constants.rows; row++) { for (int column = 0; column < s_Constants.columns; column++) { GameObject newTile = null; newTile = Get_Specific_Tile_Or_Card(premadeLevel[row, column]); Instantiate_And_Place_New_Tile(row, column, newTile); } } Setup_Spawn_Positions(); }
public static List <GameObject> checkVerticalThree(int row, int column, s_TileArray tiles) { if (row <= s_Constants.rows - 4) { if (tiles[row, column].GetComponent <s_Tiles>(). Is_Same_Type(tiles[row + 1, column].GetComponent <s_Tiles>()) && tiles[row, column].GetComponent <s_Tiles>(). Is_Same_Type(tiles[row + 3, column].GetComponent <s_Tiles>())) { return(new List <GameObject>() { tiles[row, column], tiles[row + 1, column], tiles[row + 3, column] }); } } if (row >= 2 && row <= s_Constants.rows - 2) { if (tiles[row, column].GetComponent <s_Tiles>(). Is_Same_Type(tiles[row + 1, column].GetComponent <s_Tiles>()) && tiles[row, column].GetComponent <s_Tiles>(). Is_Same_Type(tiles[row - 2, column].GetComponent <s_Tiles>())) { return(new List <GameObject>() { tiles[row, column], tiles[row + 1, column], tiles[row - 2, column] }); } } return(null); }
public static string Get_Array_Contents(s_TileArray tiles) { string empty = string.Empty; for (int row = s_Constants.rows - 1; row >= 0; row--) { for (int column = 0; column < s_Constants.columns; column++) { if (tiles[row, column] == null) { empty += "NULL |"; } else { var tile = tiles[row, column].GetComponent <s_Tiles>(); empty += tile.row.ToString("D2") + "-" + tile.column.ToString("D2"); empty += tile.Type.Substring(5, 2); if (s_Card_Utilities.Includes_Remove_Whole_Row_Column(tile.Card)) { empty += "B"; } else { empty += " "; } empty += " | "; } } empty += Environment.NewLine; } return(empty); }
public static List <GameObject> checkHorizontalThree(int row, int column, s_TileArray tiles) { if (column <= s_Constants.columns - 4) { if (tiles[row, column].GetComponent <s_Tiles>(). Is_Same_Type(tiles[row, column + 1].GetComponent <s_Tiles>()) && tiles[row, column].GetComponent <s_Tiles>(). Is_Same_Type(tiles[row, column + 3].GetComponent <s_Tiles>())) { return(new List <GameObject>() { tiles[row, column], tiles[row, column + 1], tiles[row, column + 3] }); } } if (column >= 2 && column <= s_Constants.columns - 2) { if (tiles[row, column].GetComponent <s_Tiles>(). Is_Same_Type(tiles[row, column + 1].GetComponent <s_Tiles>()) && tiles[row, column].GetComponent <s_Tiles>(). Is_Same_Type(tiles[row, column - 2].GetComponent <s_Tiles>())) { return(new List <GameObject>() { tiles[row, column], tiles[row, column + 1], tiles[row, column - 2] }); } } return(null); }
public static IEnumerable <GameObject> Find_Next_Match(s_TileArray tileArray) { List <List <GameObject> > matches = new List <List <GameObject> >(); for (int matchRow = 0; matchRow < s_Constants.rows; matchRow++) { for (int matchColumn = 0; matchColumn < s_Constants.columns; matchColumn++) { var matchOne = checkHorizontalOne(matchRow, matchColumn, tileArray); var matchTwo = checkHorizontalTwo(matchRow, matchColumn, tileArray); var matchThree = checkHorizontalThree(matchRow, matchColumn, tileArray); var matchFour = checkVerticalOne(matchRow, matchColumn, tileArray); var matchFive = checkVerticalTwo(matchRow, matchColumn, tileArray); var matchSix = checkVerticalThree(matchRow, matchColumn, tileArray); if (matchOne != null) { matches.Add(matchOne); } if (matchTwo != null) { matches.Add(matchTwo); } if (matchThree != null) { matches.Add(matchThree); } if (matchFour != null) { matches.Add(matchFour); } if (matchFive != null) { matches.Add(matchFive); } if (matchSix != null) { matches.Add(matchSix); } if (matches.Count >= 3) { return(matches[UnityEngine.Random.Range(0, matches.Count - 1)]); } if (matchRow >= s_Constants.rows / 2 && matches.Count > 0 && matches.Count <= 2) { return(matches[UnityEngine.Random.Range(0, matches.Count - 1)]); } } } return(null); }
private IEnumerator Check_Potential_Matches() { yield return(new WaitForSeconds(s_Constants.timeBeforeMatchCheck)); potentialMatches = s_GameUtilities.Find_Next_Match(tiles); if (potentialMatches != null) { while (true) { AnimatePotentialMatchesCoroutine = s_GameUtilities.Game_Utilities(potentialMatches); StartCoroutine(AnimatePotentialMatchesCoroutine); yield return(new WaitForSeconds(s_Constants.timeBeforeMatchCheck)); } } if (potentialMatches == null) { Destroy_All_Tiles(); tiles = new s_TileArray(); SpawnPositions = new Vector2[s_Constants.columns]; var premadeLevel = s_Debugging.Fill_Tiles_Array(); for (int row = 0; row < s_Constants.rows; row++) { for (int column = 0; column < s_Constants.columns; column++) { GameObject newTile = null; newTile = Get_Random_Tile(); Instantiate_And_Place_New_Tile(row, column, newTile); } } Setup_Spawn_Positions(); } }
public static List <GameObject> checkVerticalOne(int row, int column, s_TileArray tiles) { if (row <= s_Constants.rows - 2) { if (tiles[row, column].GetComponent <s_Tiles>(). Is_Same_Type(tiles[row + 1, column].GetComponent <s_Tiles>())) { if (column >= 1 && row >= 1) { if (tiles[row, column].GetComponent <s_Tiles>(). Is_Same_Type(tiles[row - 1, column - 1].GetComponent <s_Tiles>())) { return(new List <GameObject>() { tiles[row, column], tiles[row + 1, column], tiles[row - 1, column - 1] }); } } if (column <= s_Constants.columns - 2 && row >= 1) { if (tiles[row, column].GetComponent <s_Tiles>(). Is_Same_Type(tiles[row - 1, column + 1].GetComponent <s_Tiles>())) { return(new List <GameObject>() { tiles[row, column], tiles[row + 1, column], tiles[row - 1, column + 1] }); } } } } return(null); }
public static List <GameObject> checkHorizontalTwo(int row, int column, s_TileArray tiles) { if (column <= s_Constants.columns - 3) { if (tiles[row, column].GetComponent <s_Tiles>(). Is_Same_Type(tiles[row, column + 1].GetComponent <s_Tiles>())) { if (row >= 1 && column <= s_Constants.columns - 3) { if (tiles[row, column].GetComponent <s_Tiles>(). Is_Same_Type(tiles[row - 1, column + 2].GetComponent <s_Tiles>())) { return(new List <GameObject>() { tiles[row, column], tiles[row, column + 1], tiles[row - 1, column + 2] }); } } if (row <= s_Constants.rows - 2 && column <= s_Constants.columns - 3) { if (tiles[row, column].GetComponent <s_Tiles>(). Is_Same_Type(tiles[row + 1, column + 2].GetComponent <s_Tiles>())) { return(new List <GameObject>() { tiles[row, column], tiles[row, column + 1], tiles[row + 1, column + 2] }); } } } } return(null); }
public void Initialise_Tile_And_Spawn_Positions() { Initialise_Variables(); if (tiles != null) { Destroy_All_Tiles(); } tiles = new s_TileArray(); SpawnPositions = new Vector2[s_Constants.columns]; for (int row = 0; row < s_Constants.rows; row++) { for (int columns = 0; columns < s_Constants.columns; columns++) { GameObject newTile = Get_Random_Tile(); while (columns >= 2 && tiles[row, columns - 1].GetComponent <s_Tiles>().Is_Same_Type(newTile.GetComponent <s_Tiles>()) && tiles[row, columns - 2].GetComponent <s_Tiles>().Is_Same_Type(newTile.GetComponent <s_Tiles>())) { newTile = Get_Random_Tile(); } while (row >= 2 && tiles[row - 1, columns].GetComponent <s_Tiles>().Is_Same_Type(newTile.GetComponent <s_Tiles>()) && tiles[row - 2, columns].GetComponent <s_Tiles>().Is_Same_Type(newTile.GetComponent <s_Tiles>())) { newTile = Get_Random_Tile(); } Instantiate_And_Place_New_Tile(row, columns, newTile); } } Setup_Spawn_Positions(); }
public static void ShowArray(s_TileArray tiles) { Debug.Log(Get_Array_Contents(tiles)); }