public List <GamePiece> GetMatch(GamePiece piece, int newX, int newY) { if (piece.IsColored()) { ColorPeice.ColorType color = piece.ColorComponent.Color; List <GamePiece> horizontalPieces = new List <GamePiece>(); List <GamePiece> verticalPieces = new List <GamePiece>(); List <GamePiece> matchingPieces = new List <GamePiece>(); // Para checar primero en el eje horizontal horizontalPieces.Add(piece); for (int dir = 0; dir <= 1; dir++) { for (int xOffset = 1; xOffset < xDim; xOffset++) { int x; if (dir == 0) { // izquierda x = newX - xOffset; } else { // derecha x = newX + xOffset; } if (x < 0 || x >= xDim) { break; } if (pieces[x, newY].IsColored() && pieces[x, newY].ColorComponent.Color == color) { horizontalPieces.Add(pieces[x, newY]); } else { break; } } } if (horizontalPieces.Count >= 3) { for (int i = 0; i < horizontalPieces.Count; i++) { matchingPieces.Add(horizontalPieces[i]); } } if (matchingPieces.Count >= 3) { return(matchingPieces); } // Si llega aquí, nos toca checar en el eje vertical verticalPieces.Add(piece); for (int dir = 0; dir <= 1; dir++) { for (int yOffset = 1; yOffset < yDim; yOffset++) { int y; if (dir == 0) { // Arriba y = newY - yOffset; } else { // Abajo y = newY + yOffset; } if (y < 0 || y >= yDim) { break; } if (pieces[newX, y].IsColored() && pieces[newX, y].ColorComponent.Color == color) { verticalPieces.Add(pieces[newX, y]); } else { break; } } } if (verticalPieces.Count >= 3) { for (int i = 0; i < verticalPieces.Count; i++) { matchingPieces.Add(verticalPieces[i]); } } if (matchingPieces.Count >= 3) { return(matchingPieces); } } return(null); }
public List <GamePiece> GetMatch(GamePiece piece, int newX, int newY) { if (piece.IsColored()) { ColorPeice.ColorType color = piece.ColorComponent.Color; List <GamePiece> horizontalPieces = new List <GamePiece>(); List <GamePiece> verticalPieces = new List <GamePiece>(); List <GamePiece> matchingPieces = new List <GamePiece>(); // Para checar primero en el eje horizontal horizontalPieces.Add(piece); for (int dir = 0; dir <= 1; dir++) { for (int xOffset = 1; xOffset < xDim; xOffset++) { int x; if (dir == 0) { // izquierda x = newX - xOffset; } else { // derecha x = newX + xOffset; } if (x < 0 || x >= xDim) { break; } if ((pieces[x, newY].IsColored()) && (pieces[x, newY].ColorComponent.Color.Equals(color))) { horizontalPieces.Add(pieces[x, newY]); } else if ((pieces[x, newY].IsTarget()) && (pieces[x, newY].TargetComponent.Target.Equals(color))) { horizontalPieces.Add(pieces[x, newY]); } else if ((pieces[x, newY].IsChamp()) && (pieces[x, newY].ChampComponent.Champ.Equals(color))) { horizontalPieces.Add(pieces[x, newY]); } else if ((pieces[x, newY].IsBomba()) && (pieces[x, newY].BombaComponent.BombaRef.Equals(color))) { horizontalPieces.Add(pieces[x, newY]); } else { break; } } } if (horizontalPieces.Count >= 3) { for (int i = 0; i < horizontalPieces.Count; i++) { matchingPieces.Add(horizontalPieces[i]); } } if (matchingPieces.Count >= 3) { return(matchingPieces); } // Si llega aquí, nos toca checar en el eje vertical verticalPieces.Add(piece); for (int dir = 0; dir <= 1; dir++) { for (int yOffset = 1; yOffset < yDim; yOffset++) { int y; if (dir == 0) { // Arriba y = newY - yOffset; } else { // Abajo y = newY + yOffset; } if (y < 0 || y >= yDim) { break; } if ((pieces[newX, y].IsColored()) && (pieces[newX, y].ColorComponent.Color.Equals(color))) { //print(pieces[newX, y].ColorComponent.Color); verticalPieces.Add(pieces[newX, y]); } else if ((pieces[newX, y].IsTarget()) && (pieces[newX, y].TargetComponent.Target.Equals(color))) { //print(pieces[newX, y].TargetComponent.Target); verticalPieces.Add(pieces[newX, y]); } else if ((pieces[newX, y].IsChamp()) && (pieces[newX, y].ChampComponent.Champ.Equals(color))) { verticalPieces.Add(pieces[newX, y]); } else if ((pieces[newX, y].IsBomba()) && (pieces[newX, y].BombaComponent.BombaRef.Equals(color))) { //print(pieces[newX, y].BombaComponent.BombaRef); verticalPieces.Add(pieces[newX, y]); } else { break; } } } if (verticalPieces.Count >= 3) { for (int i = 0; i < verticalPieces.Count; i++) { matchingPieces.Add(verticalPieces[i]); } } if (matchingPieces.Count >= 3) { return(matchingPieces); } } if (piece.IsChamp()) { ChampPiece.ChampType champ = piece.ChampComponent.Champ; List <GamePiece> horizontalPieces = new List <GamePiece>(); List <GamePiece> verticalPieces = new List <GamePiece>(); List <GamePiece> matchingPieces = new List <GamePiece>(); // Para checar primero en el eje horizontal horizontalPieces.Add(piece); for (int dir = 0; dir <= 1; dir++) { for (int xOffset = 1; xOffset < xDim; xOffset++) { int x; if (dir == 0) { // izquierda x = newX - xOffset; } else { // derecha x = newX + xOffset; } if (x < 0 || x >= xDim) { break; } if ((pieces[x, newY].IsColored()) && (pieces[x, newY].ColorComponent.Color.Equals(champ))) { horizontalPieces.Add(pieces[x, newY]); } else if ((pieces[x, newY].IsTarget()) && (pieces[x, newY].TargetComponent.Target.Equals(champ))) { horizontalPieces.Add(pieces[x, newY]); } else if ((pieces[x, newY].IsChamp()) && (pieces[x, newY].ChampComponent.Champ.Equals(champ))) { horizontalPieces.Add(pieces[x, newY]); } else if ((pieces[x, newY].IsBomba()) && (pieces[x, newY].BombaComponent.BombaRef.Equals(champ))) { horizontalPieces.Add(pieces[x, newY]); } else { break; } } } if (horizontalPieces.Count >= 3) { for (int i = 0; i < horizontalPieces.Count; i++) { matchingPieces.Add(horizontalPieces[i]); } } if (matchingPieces.Count >= 3) { return(matchingPieces); } // Si llega aquí, nos toca checar en el eje vertical verticalPieces.Add(piece); for (int dir = 0; dir <= 1; dir++) { for (int yOffset = 1; yOffset < yDim; yOffset++) { int y; if (dir == 0) { // Arriba y = newY - yOffset; } else { // Abajo y = newY + yOffset; } if (y < 0 || y >= yDim) { break; } if ((pieces[newX, y].IsColored()) && (pieces[newX, y].ColorComponent.Color.Equals(champ))) { print(pieces[newX, y].ColorComponent.Color); verticalPieces.Add(pieces[newX, y]); } else if ((pieces[newX, y].IsTarget()) && (pieces[newX, y].TargetComponent.Target.Equals(champ))) { //print(pieces[newX, y].TargetComponent.Target); verticalPieces.Add(pieces[newX, y]); } else if ((pieces[newX, y].IsChamp()) && (pieces[newX, y].ChampComponent.Champ.Equals(champ))) { //print(pieces[newX, y].ChampComponent.Champ); verticalPieces.Add(pieces[newX, y]); } else if ((pieces[newX, y].IsBomba()) && (pieces[newX, y].BombaComponent.BombaRef.Equals(champ))) { //print(pieces[newX, y].BombaComponent.BombaRef); verticalPieces.Add(pieces[newX, y]); } else { break; } } } if (verticalPieces.Count >= 3) { for (int i = 0; i < verticalPieces.Count; i++) { matchingPieces.Add(verticalPieces[i]); } } if (matchingPieces.Count >= 3) { return(matchingPieces); } } if (piece.IsBomba()) { Bomba.BombaType color = piece.BombaComponent.BombaRef; List <GamePiece> horizontalPieces = new List <GamePiece>(); List <GamePiece> verticalPieces = new List <GamePiece>(); List <GamePiece> matchingPieces = new List <GamePiece>(); // Para checar primero en el eje horizontal horizontalPieces.Add(piece); for (int dir = 0; dir <= 1; dir++) { for (int xOffset = 1; xOffset < xDim; xOffset++) { int x; if (dir == 0) { // izquierda x = newX - xOffset; } else { // derecha x = newX + xOffset; } if (x < 0 || x >= xDim) { break; } if ((pieces[x, newY].IsColored()) && (pieces[x, newY].ColorComponent.Color.Equals(color))) { horizontalPieces.Add(pieces[x, newY]); } else if ((pieces[x, newY].IsTarget()) && (pieces[x, newY].TargetComponent.Target.Equals(color))) { horizontalPieces.Add(pieces[x, newY]); } else if ((pieces[x, newY].IsChamp()) && (pieces[x, newY].ChampComponent.Champ.Equals(color))) { horizontalPieces.Add(pieces[x, newY]); } else if ((pieces[x, newY].IsBomba()) && (pieces[x, newY].BombaComponent.BombaRef.Equals(color))) { horizontalPieces.Add(pieces[x, newY]); } else { break; } } } if (horizontalPieces.Count >= 3) { for (int i = 0; i < horizontalPieces.Count; i++) { matchingPieces.Add(horizontalPieces[i]); } } if (matchingPieces.Count >= 3) { return(matchingPieces); } // Si llega aquí, nos toca checar en el eje vertical verticalPieces.Add(piece); for (int dir = 0; dir <= 1; dir++) { for (int yOffset = 1; yOffset < yDim; yOffset++) { int y; if (dir == 0) { // Arriba y = newY - yOffset; } else { // Abajo y = newY + yOffset; } if (y < 0 || y >= yDim) { break; } if ((pieces[newX, y].IsColored()) && (pieces[newX, y].ColorComponent.Color.Equals(color))) { // print(pieces[newX, y].ColorComponent.Color); verticalPieces.Add(pieces[newX, y]); } else if ((pieces[newX, y].IsTarget()) && (pieces[newX, y].TargetComponent.Target.Equals(color))) { //print(pieces[newX, y].TargetComponent.Target); verticalPieces.Add(pieces[newX, y]); } else if ((pieces[newX, y].IsChamp()) && (pieces[newX, y].ChampComponent.Champ.Equals(color))) { //print(pieces[newX, y].ChampComponent.Champ); verticalPieces.Add(pieces[newX, y]); } else if ((pieces[newX, y].IsBomba()) && (pieces[newX, y].BombaComponent.BombaRef.Equals(color))) { print(pieces[newX, y].BombaComponent.BombaRef); verticalPieces.Add(pieces[newX, y]); } else { break; } } } if (verticalPieces.Count >= 3) { for (int i = 0; i < verticalPieces.Count; i++) { matchingPieces.Add(verticalPieces[i]); } } if (matchingPieces.Count >= 3) { return(matchingPieces); } } if (piece.IsTarget()) { TargetPiece.TargetType color = piece.TargetComponent.Target; List <GamePiece> horizontalPieces = new List <GamePiece>(); List <GamePiece> verticalPieces = new List <GamePiece>(); List <GamePiece> matchingPieces = new List <GamePiece>(); // Para checar primero en el eje horizontal horizontalPieces.Add(piece); for (int dir = 0; dir <= 1; dir++) { for (int xOffset = 1; xOffset < xDim; xOffset++) { int x; if (dir == 0) { // izquierda x = newX - xOffset; } else { // derecha x = newX + xOffset; } if (x < 0 || x >= xDim) { break; } if ((pieces[x, newY].IsColored()) && (pieces[x, newY].ColorComponent.Color.Equals(color))) { horizontalPieces.Add(pieces[x, newY]); } else if ((pieces[x, newY].IsTarget()) && (pieces[x, newY].TargetComponent.Target.Equals(color))) { horizontalPieces.Add(pieces[x, newY]); } else if ((pieces[x, newY].IsChamp()) && (pieces[x, newY].ChampComponent.Champ.Equals(color))) { horizontalPieces.Add(pieces[x, newY]); } else if ((pieces[x, newY].IsBomba()) && (pieces[x, newY].BombaComponent.BombaRef.Equals(color))) { horizontalPieces.Add(pieces[x, newY]); } else { break; } } } if (horizontalPieces.Count >= 3) { for (int i = 0; i < horizontalPieces.Count; i++) { matchingPieces.Add(horizontalPieces[i]); } } if (matchingPieces.Count >= 3) { return(matchingPieces); } // Si llega aquí, nos toca checar en el eje vertical verticalPieces.Add(piece); for (int dir = 0; dir <= 1; dir++) { for (int yOffset = 1; yOffset < yDim; yOffset++) { int y; if (dir == 0) { // Arriba y = newY - yOffset; } else { // Abajo y = newY + yOffset; } if (y < 0 || y >= yDim) { break; } if ((pieces[newX, y].IsColored()) && (pieces[newX, y].ColorComponent.Color.Equals(color))) { print(pieces[newX, y].ColorComponent.Color); verticalPieces.Add(pieces[newX, y]); } else if ((pieces[newX, y].IsTarget()) && (pieces[newX, y].TargetComponent.Target.Equals(color))) { print(pieces[newX, y].TargetComponent.Target); verticalPieces.Add(pieces[newX, y]); } else if ((pieces[newX, y].IsChamp()) && (pieces[newX, y].ChampComponent.Champ.Equals(color))) { print(pieces[newX, y].ChampComponent.Champ); verticalPieces.Add(pieces[newX, y]); } else if ((pieces[newX, y].IsBomba()) && (pieces[newX, y].BombaComponent.BombaRef.Equals(color))) { print(pieces[newX, y].BombaComponent.BombaRef); verticalPieces.Add(pieces[newX, y]); } else { break; } } } if (verticalPieces.Count >= 3) { for (int i = 0; i < verticalPieces.Count; i++) { matchingPieces.Add(verticalPieces[i]); } } if (matchingPieces.Count >= 3) { return(matchingPieces); } } return(null); }