public static List <GameObject> CheckVertical3(int row, int column, ShapesArray_4 shapes) { if (row <= ConstantsVariable_4.Rows - 4) { if (shapes[row, column].GetComponent <Shape_4>(). IsSameType(shapes[row + 1, column].GetComponent <Shape_4>()) && shapes[row, column].GetComponent <Shape_4>(). IsSameType(shapes[row + 3, column].GetComponent <Shape_4>())) { return(new List <GameObject>() { shapes[row, column], shapes[row + 1, column], shapes[row + 3, column] }); } } if (row >= 2 && row <= ConstantsVariable_4.Rows - 2) { if (shapes[row, column].GetComponent <Shape_4>(). IsSameType(shapes[row + 1, column].GetComponent <Shape_4>()) && shapes[row, column].GetComponent <Shape_4>(). IsSameType(shapes[row - 2, column].GetComponent <Shape_4>())) { return(new List <GameObject>() { shapes[row, column], shapes[row + 1, column], shapes[row - 2, column] }); } } return(null); }
public static List <GameObject> CheckHorizontal3(int row, int column, ShapesArray_4 shapes) { if (column <= ConstantsVariable_4.Columns - 4) { if (shapes[row, column].GetComponent <Shape_4>(). IsSameType(shapes[row, column + 1].GetComponent <Shape_4>()) && shapes[row, column].GetComponent <Shape_4>(). IsSameType(shapes[row, column + 3].GetComponent <Shape_4>())) { return(new List <GameObject>() { shapes[row, column], shapes[row, column + 1], shapes[row, column + 3] }); } } if (column >= 2 && column <= ConstantsVariable_4.Columns - 2) { if (shapes[row, column].GetComponent <Shape_4>(). IsSameType(shapes[row, column + 1].GetComponent <Shape_4>()) && shapes[row, column].GetComponent <Shape_4>(). IsSameType(shapes[row, column - 2].GetComponent <Shape_4>())) { return(new List <GameObject>() { shapes[row, column], shapes[row, column + 1], shapes[row, column - 2] }); } } return(null); }
/// Will check for potential matches vertically and horizontally public static IEnumerable <GameObject> GetPotentialMatches(ShapesArray_4 shapes) { //list that will contain all the matches we find List <List <GameObject> > matches = new List <List <GameObject> >(); for (int row = 0; row < ConstantsVariable_4.Rows; row++) { for (int column = 0; column < ConstantsVariable_4.Columns; column++) { var matches1 = CheckHorizontal1(row, column, shapes); var matches2 = CheckHorizontal2(row, column, shapes); var matches3 = CheckHorizontal3(row, column, shapes); var matches4 = CheckVertical1(row, column, shapes); var matches5 = CheckVertical2(row, column, shapes); var matches6 = CheckVertical3(row, column, shapes); if (matches1 != null) { matches.Add(matches1); } if (matches2 != null) { matches.Add(matches2); } if (matches3 != null) { matches.Add(matches3); } if (matches4 != null) { matches.Add(matches4); } if (matches5 != null) { matches.Add(matches5); } if (matches6 != null) { matches.Add(matches6); } //if we have >= 3 matches, return a random one if (matches.Count >= 3) { return(matches[UnityEngine.Random.Range(0, matches.Count - 1)]); } //if we are in the middle of the calculations/loops //and we have less than 3 matches, return a random one if (row >= ConstantsVariable_4.Rows / 2 && matches.Count > 0 && matches.Count <= 2) { return(matches[UnityEngine.Random.Range(0, matches.Count - 1)]); } } } return(null); }
public static List <GameObject> CheckVertical2(int row, int column, ShapesArray_4 shapes) { if (row <= ConstantsVariable_4.Rows - 3) { if (shapes[row, column].GetComponent <Shape_4>(). IsSameType(shapes[row + 1, column].GetComponent <Shape_4>())) { if (column >= 1) { if (shapes[row, column].GetComponent <Shape_4>(). IsSameType(shapes[row + 2, column - 1].GetComponent <Shape_4>())) { return new List <GameObject>() { shapes[row, column], shapes[row + 1, column], shapes[row + 2, column - 1] } } } ; if (column <= ConstantsVariable_4.Columns - 2) { if (shapes[row, column].GetComponent <Shape_4>(). IsSameType(shapes[row + 2, column + 1].GetComponent <Shape_4>())) { return new List <GameObject>() { shapes[row, column], shapes[row + 1, column], shapes[row + 2, column + 1] } } } ; } } return(null); }
//Initialize CandyAndSpawnPositions public void InitializeCandyAndSpawnPositions() { InitializeVariables(); if (shapes != null) { DestroyAllCandy(); } shapes = new ShapesArray_4(); SpawnPositions = new Vector2[ConstantsVariable_4.Columns]; for (int row = 0; row < ConstantsVariable_4.Rows; row++) { for (int column = 0; column < ConstantsVariable_4.Columns; column++) { GameObject newCandy = GetRandomCandy(); //check if two previous horizontal are of the same type while (column >= 2 && shapes[row, column - 1].GetComponent <Shape_4>() .IsSameType(newCandy.GetComponent <Shape_4>()) && shapes[row, column - 2].GetComponent <Shape_4>().IsSameType(newCandy.GetComponent <Shape_4>())) { newCandy = GetRandomCandy(); } //check if two previous vertical are of the same type while (row >= 2 && shapes[row - 1, column].GetComponent <Shape_4>() .IsSameType(newCandy.GetComponent <Shape_4>()) && shapes[row - 2, column].GetComponent <Shape_4>().IsSameType(newCandy.GetComponent <Shape_4>())) { newCandy = GetRandomCandy(); } InstantiateAndPlaceNewCandy(row, column, newCandy); } } SetupSpawnPositions(); }