void ClearMark(CellPrefabs _cell) { if (markCells.Contains(_cell)) { markCells.Remove(_cell); } }
void SetToMark(CellPrefabs _cell) { if (!markCells.Contains(_cell)) { markCells.Add(_cell); } }
void SetToDirty(CellPrefabs _cell) { if (!dirtyCells.Contains(_cell)) { dirtyCells.Add(_cell); } }
CellPrefabs GetCellByDir(CellPrefabs _cell, Dir _dir) { if (_cell == null) { return(null); } int _x = _cell.X; int _y = _cell.Y; switch (_dir) { case Dir.UP: _y -= 1; break; case Dir.DOWN: _y += 1; break; case Dir.LEFT: _x -= 1; break; case Dir.RIGHT: _x += 1; break; } if (_x < 0 || _y < 0 || _x >= LevelDatabase.Instance.colCount || _y >= LevelDatabase.Instance.rowCount) { return(null); } return(cellList[_y * LevelDatabase.Instance.colCount + _x]); }
void CancleDragSwap() { if (endDragCell && endDragFindCell) { endDragFindCell.SwapCellElement(endDragCell); endDragCell = null; endDragFindCell = null; } }
public void SwapCellElement(CellPrefabs _cell) { state = CellState.Swap; var _old = _cell.bandingElement; _cell.SwapElement(bandingElement); SwapElement(_old); }
IEnumerator MatchStep() { while (dirtyCells.Count > 0) { //等待所有dirtycell都idel //yield return StartCoroutine(WaitForDirtyCellsToIdel()); var it = WaitForDirtyCellsToIdel(); while (it.MoveNext()) { yield return(null); } //检测是不是要消除元素 ClearMarkCells(); DoMatch(); if (markCells.Count > 0) { //要消除 //消除,然后继续进行后面的逻辑 endDragFindCell = null; endDragCell = null; ClearDirtyCells(); } else { //不消除 //换位,然后结束判断流程 CancleDragSwap(); //yield return StartCoroutine(WaitForDirtyCellsToIdel()); it = WaitForDirtyCellsToIdel(); while (it.MoveNext()) { yield return(null); } ClearDirtyCells(); break; } ClearDirtyCells(); //将markCells中的元素回收 RecyleMarkCell(); it = WaitForMarkCellsToIdel(); while (it.MoveNext()) { yield return(null); } //将回收后空的cell进行上方元素的掉落填充,填充的元素依然是diry状态 FallElement(); //go to stop 1 } state = GameState.Ready; yield return(null); }
public static bool IsSpecialMatch(CellPrefabs _cell, int v, int h) { SpecialMatch _sm = new SpecialMatch(); _sm.markCellcountV = v; _sm.markCellcountH = h; _sm.targetCell = _cell; _sm.CheckEleState(); if (_sm._eleState > ElementState.Normal) { _sm.targetCell.bandingElement.IsEffected = false; _sm.targetCell.bandingElement.ChangeElementState(_sm._eleState); return(true); } return(false); }
void FallElement() { List <CellPrefabs> _emptyCell = new List <CellPrefabs>(markCells); List <CellPrefabs> _tmpNewEmptyCells = new List <CellPrefabs>(); while (_emptyCell.Count > 0) { //把_emptyCell排序,保证遍历从最大(右下角)开始 _emptyCell.Sort((x, y) => y.IndexInPanel - x.IndexInPanel); foreach (CellPrefabs _empty in _emptyCell) { CellPrefabs _tmp = _empty; while (true) { _tmp = GetCellByDir(_tmp, Dir.UP); if (_tmp != null && !_tmp.IsEmpty) { //把现在的empty向上检测哪一个是掉落目标 _empty.FallElement(_tmp); _tmpNewEmptyCells.Add(_tmp); SetToDirty(_empty); break; } else if (_tmp == null) { //找不到cell不为空,生产Element并移动 Element _newEle = ElementDatabase.Instance.RandomElement(); _newEle.transform.SetParent(elementsRoot); _empty.FallElement(_newEle); _newEle.transform.position = _empty.transform.position + new Vector3(0, CellDatabase.Instance.cellSize * 3, 0); SetToDirty(_empty); break; } } } _emptyCell.Clear(); //掉落后新的empty生产 if (_tmpNewEmptyCells.Count > 0) { _emptyCell.AddRange(_tmpNewEmptyCells); _tmpNewEmptyCells.Clear(); } } }
void OnCellDragCallback(CellPrefabs _cell, Vector2 _dirty) { if (state != GameState.Ready) { return; } float xCos = Vector2.Dot(_dirty.normalized, Vector2.right); float yCos = Vector2.Dot(_dirty.normalized, Vector2.up); CellPrefabs _findCell = null; if (Mathf.Abs(xCos) > Mathf.Abs(yCos)) { if (xCos > 0) { _findCell = GetCellByDir(_cell, Dir.RIGHT); } else { _findCell = GetCellByDir(_cell, Dir.LEFT); } } else { if (yCos > 0) { _findCell = GetCellByDir(_cell, Dir.UP); } else { _findCell = GetCellByDir(_cell, Dir.DOWN); } } if (_findCell) { state = GameState.Swap; _cell.SwapCellElement(_findCell); endDragCell = _cell; endDragFindCell = _findCell; SetToDirty(endDragCell); SetToDirty(endDragFindCell); StartCoroutine(MatchStep()); } }
void GetsameCellsH(CellPrefabs _cell, out List <CellPrefabs> ret, bool ignoreSame = false) { List <CellPrefabs> _ret = new List <CellPrefabs>() { _cell }; int _targetType = _cell.bandingElement.Type; CellPrefabs _tmp = _cell; while (true) { _tmp = GetCellByDir(_tmp, Dir.LEFT); if (_tmp && !_tmp.IsEmpty && (_tmp.bandingElement.Type == _targetType || ignoreSame)) { _ret.Add(_tmp); } else { break; } } _tmp = _cell; while (true) { _tmp = GetCellByDir(_tmp, Dir.RIGHT); if (_tmp && !_tmp.IsEmpty && (_tmp.bandingElement.Type == _targetType || ignoreSame)) { _ret.Add(_tmp); } else { break; } } ret = _ret; }
public void FallElement(CellPrefabs _other) { bandingElement = _other.bandingElement; _other.bandingElement = null; DropElement(bandingElement); }