public void CellEventHandler() { foreach (GrideCell grideCell in GrideCells) { grideCell.objectShape.onMouseDownAction = (cell) => { if (selectedOne == null) { selectedOne = cell; selectedOne.objectShape.SetSelctedState(); return; } if (selectedOne != null && selectedTwo == null) { selectedTwo = cell; selectedTwo.objectShape.SetSelctedState(); //计算 if (Macth()) { MatchSuccess(); } else { MatchFail(); } } }; } }
bool NoPoint(GrideCell selectedOne, GrideCell selectedTwo) { bool flag = false; if (selectedOne.x == selectedTwo.x) { int min = Mathf.Min(selectedOne.y, selectedTwo.y); int max = Mathf.Max(selectedOne.y, selectedTwo.y); bool flag1 = true; for (int i = min + 1; i < max; i++) { flag1 &= GetGrideCell(selectedOne.x, i).CellIsNull; } flag = flag1; } if (selectedOne.y == selectedTwo.y) { int min = Mathf.Min(selectedOne.x, selectedTwo.x); int max = Mathf.Max(selectedOne.x, selectedTwo.x); bool flag1 = true; for (int i = min + 1; i < max; i++) { flag1 &= GetGrideCell(i, selectedOne.y).CellIsNull; } flag = flag1; } return(flag); }
void MatchFail() { if (drawline != null) { StopCoroutine(drawline); } drawline = StartCoroutine(DrawLine(() => { selectedOne.objectShape.SetNotSelectedState(); selectedTwo.objectShape.SetNotSelectedState(); selectedOne = null; selectedTwo = null; macthList.Clear(); })); }
bool TwoPoint(out GrideCell p0, out GrideCell p1) { bool flag = false; p0 = null; p1 = null; GrideCell temp; foreach (GrideCell grideCell in GrideCells) { if (OnePoint(selectedOne, grideCell, out temp)) { p0 = temp; if (grideCell.CellIsNull) { if (NoPoint(grideCell, selectedTwo)) { flag = true; p1 = grideCell; } } } } if (flag) { return(flag); } foreach (GrideCell grideCell in GrideCells) { if (OnePoint(selectedTwo, grideCell, out temp)) { p0 = temp; if (grideCell.CellIsNull) { if (NoPoint(grideCell, selectedOne)) { flag = true; p1 = grideCell; } } } } return(flag); }
bool OnePoint(GrideCell selectedOne, GrideCell selectedTwo, out GrideCell p) { bool flag = false; p = null; foreach (GrideCell grideCell in GrideCells) { if (NoPoint(selectedOne, grideCell) && NoPoint(selectedTwo, grideCell)) { if (grideCell.CellIsNull) { flag = true; p = grideCell; } } } return(flag); }
void MatchSuccess() { if (drawline != null) { StopCoroutine(drawline); } drawline = StartCoroutine(DrawLine(() => { selectedOne.objectShape.PairHandler(); selectedTwo.objectShape.PairHandler(); print("selectedOne>x:" + selectedOne.x + " y:" + selectedOne.y); print("selectedTwo>x:" + selectedTwo.x + " y:" + selectedTwo.y); selectedOne = null; selectedTwo = null; macthList.Clear(); })); }
public GrideCell GetGridePosByWorldPos(Vector3 worlPos) { GrideCell cell = null; for (int i = 0; i < GrideCells.Count; i++) { int j = grideCells[i].x + 1; int k = GrideCells[i].y + 1; GrideCell cornorCell = GetGrideCell(j, k); if (cornorCell != null) { if (GrideCells[i].pos.x < worlPos.x && worlPos.x < cornorCell.x && GrideCells[i].pos.z < worlPos.z && worlPos.z < cornorCell.pos.z) { cell = grideCells[i]; } } } return(cell); }
public void GenerateMap() { foreach (var grideCell in GrideCells) { Util.SafeDestroy(grideCell.objectShape); } grideCells.Clear(); for (int i = 0; i < horCount; i++) { for (int j = 0; j < verCount; j++) { GrideCell cell = new GrideCell(i, j); cell.pos = startCornor + new Vector3(cell.x * cellUnit, cell.y * cellUnit, 0) + new Vector3((i + 1) * space, (j + 1) * space, 0); GameObject obj = Instantiate(target.gameObject, cell.pos, Quaternion.identity); obj.transform.SetParent(canvasParent); ObjectShape objectShape = obj.GetComponent <ObjectShape>(); objectShape.grideCell = cell; cell.SetObjctShade(objectShape); objectShape.SetValue(Random.Range(1, 5).ToString()); grideCells.Add(cell); } } }