//创建方块对象 public void SpawnNewPiece(int x, int y, CodeType type) { GameObject code = Instantiate(piecePrefabDict[type], NumToVector(x, y), Quaternion.identity); code.transform.parent = transform; CodePrefab codePrefab = code.GetComponent <CodePrefab>(); codePrefab.initPos(x, y, this, type); gridCodes[x, y] = codePrefab; }
//滑动手势判断 public void UpCode() { if (GetComponent <SystemUI>().IsGame) { if (StartCode != null && EndCode != null) { int X = EndCode.getX - StartCode.getX; int Y = EndCode.getY - StartCode.getY; //横轴滑动 if (Mathf.Abs(X) > Mathf.Abs(Y)) { //右滑 if (X > 0) { Debug.Log("向右滑动"); EndCode = gridCodes[StartCode.getX + 1, StartCode.getY]; } //左滑 else if (X < 0) { Debug.Log("向左滑动"); EndCode = gridCodes[StartCode.getX - 1, StartCode.getY]; } } //纵轴滑动 else if (Mathf.Abs(X) < Mathf.Abs(Y)) { if (Y > 0) { Debug.Log("向下滑动"); EndCode = gridCodes[StartCode.getX, StartCode.getY + 1]; } else if (Y < 0) { Debug.Log("向上滑动"); EndCode = gridCodes[StartCode.getX, StartCode.getY - 1]; } } else { EndCode = null; } StartCoroutine(MoveCode()); StartCode = null; EndCode = null; } } }
//行单位填充空节点 private bool fillRow() { //用于判断是否全部填充 bool isNeed = true; for (int i = 0; i < Grid_H; i++) { for (int y = 0; y < Grid_V; y++) { //判断当前结点是否为空节点 if (gridCodes[i, y].getCodeType == CodeType.EMPTY) { isNeed = false; Destroy(gridCodes[i, y].gameObject); GameObject code = Instantiate(piecePrefabDict[CodeType.NORMAL], NumToVector(i, -1), Quaternion.identity); code.transform.parent = transform; CodePrefab codePrefab = code.GetComponent <CodePrefab>(); codePrefab.initPos(i, -1, this, CodeType.NORMAL); codePrefab.getColorComponent.setRangeSprite(); for (int c = y - 1; c >= 0; c--) { gridCodes[i, c].getMoveComponent.MoveToPos(i, c + 1, fillTime); gridCodes[i, c + 1] = gridCodes[i, c]; } codePrefab.getMoveComponent.MoveToPos(i, 0, fillTime); gridCodes[i, 0] = codePrefab; break; } } } return(isNeed); }
public void initMoveCompent(CodePrefab code) { codePrefab = code; }
public void EnterCode(CodePrefab eCode) { EndCode = eCode; }
public void DownCode(CodePrefab sCode) { StartCode = sCode; }
//匹配当前指定对象是否有消除的对象 public List <CodePrefab> getMatch(CodePrefab code, int x, int y) { List <CodePrefab> codeMatch = new List <CodePrefab>(); List <CodePrefab> horizontalCode = new List <CodePrefab>(); List <CodePrefab> verticalCode = new List <CodePrefab>(); bool isH = false; bool isV = false; if (code.getCodeType == CodeType.EMPTY) { return(codeMatch); } //右遍历 for (int i = x + 1; i < Grid_H; i++) { if (code.getX == i && code.getY == y) { break; } if (gridCodes[i, y].getCodeType != CodeType.EMPTY && gridCodes[i, y].getColorComponent.getColor == code.getColorComponent.getColor) { horizontalCode.Add(gridCodes[i, y]); } else { break; } } //左遍历 for (int i = x - 1; i >= 0; i--) { if (code.getX == i && code.getY == y) { break; } if (gridCodes[i, y].getCodeType != CodeType.EMPTY && gridCodes[i, y].getColorComponent.getColor == code.getColorComponent.getColor) { horizontalCode.Add(gridCodes[i, y]); } else { break; } } //下遍历 for (int i = y + 1; i < Grid_V; i++) { if (code.getX == x && code.getY == i) { break; } if (gridCodes[x, i].getCodeType != CodeType.EMPTY && gridCodes[x, i].getColorComponent.getColor == code.getColorComponent.getColor) { verticalCode.Add(gridCodes[x, i]); } else { break; } } //上遍历 for (int i = y - 1; i >= 0; i--) { if (code.getX == x && code.getY == i) { break; } if (gridCodes[x, i].getCodeType != CodeType.EMPTY && gridCodes[x, i].getColorComponent.getColor == code.getColorComponent.getColor) { verticalCode.Add(gridCodes[x, i]); } else { break; } } if (horizontalCode.Count >= 2) { isH = true; foreach (CodePrefab c in horizontalCode) { //Debug.Log("横轴 颜色 : " + c.getColorComponent.getColor + "坐标: " + c.getX + "," + c.getY); codeMatch.Add(c); } } if (verticalCode.Count >= 2) { isV = true; foreach (CodePrefab c in verticalCode) { //Debug.Log("纵轴 颜色 : " + c.getColorComponent.getColor + "坐标: " + c.getX + "," + c.getY); codeMatch.Add(c); } } if (isH || isV) { //Debug.Log("颜色 : " + code.getColorComponent.getColor + "坐标: " + x + "," + y); codeMatch.Add(code); } return(codeMatch); }