// Update is called once per frames void Update() { int[] arr = new int[] { 0, 4, 5, 4, 5, 0, 0, 3, 3, 3, 4, 0, 0, 2, 2, 2, 3, 0, 1, 0, 0, 2, 0, 0 }; if (Time.time >= _creatTargetTime && flag < 24) { int idx = Random.Range(0, 5); int x = Random.Range(0, GameConfig.GAMECOLUMN); GameObject temp = Instantiate(_block); temp.GetComponent <BlockAni>().setPosByArrIdx(flag % 6, GameConfig.GAMEROW - 1); temp.GetComponent <BlockAni>()._curState = (BlockAni.BlockState.TopDown); temp.GetComponent <BlockAni>()._lastPos = new Vector2(flag % 6, GameConfig.GAMEROW - 1); temp.GetComponent <BlockAni>()._picidx = arr[flag]; _creatTargetTime = Time.time + _newBlcokDur; _arrAllBlock.Add(temp); flag++; } _curState.StateUpdate(); HandleInput(); ComboMgr.getInstance().updata(Time.deltaTime); tryDelBlocks(); }
public void tryDelBlocks() { bool haveCombo = false; for (int i = _arrNeedDelList.Count - 1; i >= 0; i--) { _arrNeedDelList[i].updateTime(); bool shouldremove = false; if (!_arrNeedDelList[i]._activity) { shouldremove = true; haveCombo = true; } if (_arrNeedDelList[i]._needRecovery) { _arrNeedDelList[i].resetState(); shouldremove = true; } if (shouldremove) { _arrNeedDelList.RemoveAt(i); } } for (int j = GameConfig.GAMEROW - 1; j >= 0; j--) { for (int i = 0; i < GameConfig.GAMECOLUMN; i++) { if (_arrSpriteIcon[i, j] != null) { BlockAni cs = (_arrSpriteIcon[i, j]).GetComponent <BlockAni>(); if (cs._curState == BlockAni.BlockState.ShouldDel) { GameObject temp = _arrSpriteIcon[i, j]; _arrAllBlock.Remove(_arrSpriteIcon[i, j]); _arrSpriteIcon[i, j] = null; Destroy(temp); } } } } if (haveCombo) { //startCombo(); ComboMgr.getInstance().sendMessage(ComboMgr.ComboMessage.END_COUNT_DOWN); checkDel(); } }
public void checkDel() { if (_curState == _moveGameState) { return; } for (int i = 0; i < _arrAllBlock.Count; i++) { BlockAni cs = (_arrAllBlock[i]).GetComponent <BlockAni>(); if (cs._curState == BlockAni.BlockState.ReDown) { return; } } List <GameObject> checklist = new List <GameObject>(); for (int row = 0; row < GameConfig.GAMEROW; row++) { for (int col = 0; col < GameConfig.GAMECOLUMN; col++) { //bool isRowHaveDeling = false; //bool isColHaveDeling = false; int delingRowIdx = -1; int delingColIdx = -1; if (_arrSpriteIcon[col, row] != null) { List <GameObject> tempColList = new List <GameObject>(); List <GameObject> tempRowList = new List <GameObject>(); BlockAni cs = _arrSpriteIcon[col, row].GetComponent <BlockAni>(); int checkPicId = cs._picidx; if (cs._curState == BlockAni.BlockState.CountDown || cs._curState == BlockAni.BlockState.ShouldDel || cs._curState == BlockAni.BlockState.MoveLR || cs._curState == BlockAni.BlockState.MoveUpDown) { continue; } if (cs._bCheckCol == true && cs._bCheckRow == true) { continue; } else { cs._bCheckCol = true; cs._bCheckRow = true; checklist.Add(_arrSpriteIcon[col, row]); } int tempCol = col + 1; while (tempCol != GameConfig.GAMECOLUMN) { if (_arrSpriteIcon[tempCol, row] != null) { BlockAni tempcs = _arrSpriteIcon[tempCol, row].GetComponent <BlockAni>(); int curId = tempcs._picidx; if (curId == checkPicId && tempcs._bCheckCol == false) { if (tempcs._curState == BlockAni.BlockState.CountDown) { delingColIdx = tempcs._uniqueId; } tempcs._bCheckCol = true; checklist.Add(_arrSpriteIcon[tempCol, row]); tempColList.Add(_arrSpriteIcon[tempCol, row]); } else { break; } } else { break; } tempCol++; } tempCol = col - 1; while (tempCol != -1) { if (_arrSpriteIcon[tempCol, row] != null) { BlockAni tempcs = _arrSpriteIcon[tempCol, row].GetComponent <BlockAni>(); int curId = tempcs._picidx; if (curId == checkPicId && tempcs._bCheckCol == false) { if (tempcs._curState == BlockAni.BlockState.CountDown) { //isColHaveDeling = true; delingColIdx = tempcs._uniqueId; } tempcs._bCheckCol = true; checklist.Add(_arrSpriteIcon[tempCol, row]); tempColList.Add(_arrSpriteIcon[tempCol, row]); } else { break; } } else { break; } tempCol--; } int tempRow = row + 1; while (tempRow != GameConfig.GAMEROW) { if (_arrSpriteIcon[col, tempRow] != null) { BlockAni tempcs = _arrSpriteIcon[col, tempRow].GetComponent <BlockAni>(); int curId = tempcs._picidx; if (curId == checkPicId && tempcs._bCheckRow == false) { if (tempcs._curState == BlockAni.BlockState.CountDown) { //isRowHaveDeling = true; delingRowIdx = tempcs._uniqueId; } tempRowList.Add(_arrSpriteIcon[col, tempRow]); tempcs._bCheckRow = true; checklist.Add(_arrSpriteIcon[col, tempRow]); } else { break; } } else { break; } tempRow++; } tempRow = row - 1; while (tempRow != -1) { if (_arrSpriteIcon[col, tempRow] != null) { BlockAni tempcs = _arrSpriteIcon[col, tempRow].GetComponent <BlockAni>(); int curId = tempcs._picidx; if (curId == checkPicId && tempcs._bCheckRow == false) { if (tempcs._curState == BlockAni.BlockState.CountDown) { //isRowHaveDeling = true; delingRowIdx = tempcs._uniqueId; } tempRowList.Add(_arrSpriteIcon[col, tempRow]); tempcs._bCheckRow = true; checklist.Add(_arrSpriteIcon[col, tempRow]); } else { break; } } else { break; } tempRow--; } bool isColNumFit = false; bool isRowNumFit = false; if (tempColList.Count >= _curNeedComboNum - 1) { isColNumFit = true; } if (tempRowList.Count >= _curNeedComboNum - 1) { isRowNumFit = true; } var temp = GameConfig.createStruct(); if (isColNumFit && !isRowNumFit) { if (delingColIdx != -1) { temp = getWaitingStructById(delingColIdx); for (int n = 0; n < tempColList.Count; n++) { temp.pushWaitingDelObject(tempColList[n]); } temp.pushWaitingDelObject(_arrSpriteIcon[col, row]); } else { for (int n = 0; n < tempColList.Count; n++) { temp.pushWaitingDelObject(tempColList[n]); } temp.pushWaitingDelObject(_arrSpriteIcon[col, row]); addWaitingForDelStruct(temp); } ComboMgr.getInstance().sendMessage(ComboMgr.ComboMessage.START_COUNT_DOWN); } else if (isRowNumFit && !isColNumFit) { if (delingRowIdx != -1) { temp = getWaitingStructById(delingRowIdx); for (int n = 0; n < tempRowList.Count; n++) { temp.pushWaitingDelObject(tempRowList[n]); } temp.pushWaitingDelObject(_arrSpriteIcon[col, row]); } else { for (int n = 0; n < tempRowList.Count; n++) { temp.pushWaitingDelObject(tempRowList[n]); } temp.pushWaitingDelObject(_arrSpriteIcon[col, row]); addWaitingForDelStruct(temp); } ComboMgr.getInstance().sendMessage(ComboMgr.ComboMessage.START_COUNT_DOWN); } else if (isRowNumFit && isColNumFit) { if (delingRowIdx != -1) { temp = getWaitingStructById(delingRowIdx); } else if (delingColIdx != -1) { temp = getWaitingStructById(delingColIdx); } else { addWaitingForDelStruct(temp); } for (int n = 0; n < tempRowList.Count; n++) { temp.pushWaitingDelObject(tempRowList[n]); } for (int n = 0; n < tempColList.Count; n++) { temp.pushWaitingDelObject(tempColList[n]); } temp.pushWaitingDelObject(_arrSpriteIcon[col, row]); ComboMgr.getInstance().sendMessage(ComboMgr.ComboMessage.START_COUNT_DOWN); } } } } for (int i = 0; i < checklist.Count; i++) { checklist[i].GetComponent <BlockAni>()._bCheckCol = false; checklist[i].GetComponent <BlockAni>()._bCheckRow = false; } checklist.Clear(); }
public override void enterState() { _targetTime = Time.time + _moveDur; GameObject[,] _arrSpriteIcon = _mainGame.GetComponent <MainGame>()._arrSpriteIcon; if (_curInputEvent == GameInputEvent.MoveLeft) { _speed.x = -_speedValue; _speed.y = 0.0f; int totalnum = GameConfig.GAMECOLUMN; int spidx = totalnum - 1; int cloneidx = 0; for (int i = 0; i < totalnum; i++) { if (_arrSpriteIcon[i, _moveConfig] != null) { _needMoveArr.Add(_arrSpriteIcon[i, _moveConfig]); } } GameObject clonetemp = null; if (_arrSpriteIcon[cloneidx, _moveConfig]) { //_arrSpriteIcon[cloneidx, _moveConfig].GetComponent<BlockAni>()._curState = (BlockAni.BlockState.Move); clonetemp = Instantiate(_arrSpriteIcon[cloneidx, _moveConfig]); BlockAni clonecs = clonetemp.GetComponent <BlockAni>(); BlockAni clonecs2 = _arrSpriteIcon[cloneidx, _moveConfig].GetComponent <BlockAni>(); clonecs._picidx = clonecs2._picidx; clonetemp.GetComponent <BlockAni>().setPosByArrIdx(totalnum, _moveConfig); _needMoveArr.Add(clonetemp); _mainGame.GetComponent <MainGame>()._arrAllBlock.Add(clonetemp); clonetemp.GetComponent <BlockAni>()._lastPos = (new Vector2(totalnum - 1, _moveConfig)); } _needDelGameObject = _arrSpriteIcon[cloneidx, _moveConfig]; for (int i = 0; i < totalnum - 1; i++) { _arrSpriteIcon[i, _moveConfig] = _arrSpriteIcon[i + 1, _moveConfig]; if (_arrSpriteIcon[i, _moveConfig] != null) { _arrSpriteIcon[i, _moveConfig].GetComponent <BlockAni>()._lastPos = (new Vector2(i, _moveConfig)); } } _arrSpriteIcon[spidx, _moveConfig] = clonetemp; } else if (_curInputEvent == GameInputEvent.MoveRight) { _speed.x = _speedValue; _speed.y = 0.0f; int totalnum = GameConfig.GAMECOLUMN; int spidx = 0; int cloneidx = totalnum - 1; for (int i = 0; i < totalnum; i++) { if (_arrSpriteIcon[i, _moveConfig] != null) { _needMoveArr.Add(_arrSpriteIcon[i, _moveConfig]); } } GameObject clonetemp = null; if (_arrSpriteIcon[cloneidx, _moveConfig]) { //_arrSpriteIcon[cloneidx, _moveConfig].GetComponent<BlockAni>()._curState = (BlockAni.BlockState.Move); clonetemp = Instantiate(_arrSpriteIcon[cloneidx, _moveConfig]); BlockAni clonecs = clonetemp.GetComponent <BlockAni>(); BlockAni clonecs2 = _arrSpriteIcon[cloneidx, _moveConfig].GetComponent <BlockAni>(); clonecs._picidx = clonecs2._picidx; clonetemp.GetComponent <BlockAni>().setPosByArrIdx(-1, _moveConfig); _needMoveArr.Add(clonetemp); _mainGame.GetComponent <MainGame>()._arrAllBlock.Add(clonetemp); clonetemp.GetComponent <BlockAni>()._lastPos = (new Vector2(spidx, _moveConfig)); } _needDelGameObject = _arrSpriteIcon[cloneidx, _moveConfig]; for (int i = totalnum - 1; i > 0; i--) { _arrSpriteIcon[i, _moveConfig] = _arrSpriteIcon[i - 1, _moveConfig]; if (_arrSpriteIcon[i, _moveConfig] != null) { _arrSpriteIcon[i, _moveConfig].GetComponent <BlockAni>()._lastPos = (new Vector2(i, _moveConfig)); } } _arrSpriteIcon[spidx, _moveConfig] = clonetemp; } else if (_curInputEvent == GameInputEvent.MoveDown) { _speed.y = -_speedValue; _speed.x = 0.0f; int totalnum = GameConfig.GAMEROW; int spidx = totalnum - 1; int cloneidx = 0; for (int i = 0; i < totalnum; i++) { if (_arrSpriteIcon[_moveConfig, i] != null) { if (_arrSpriteIcon[_moveConfig, i].GetComponent <BlockAni>()._curState == BlockAni.BlockState.Stand || _arrSpriteIcon[_moveConfig, i].GetComponent <BlockAni>()._curState == BlockAni.BlockState.CountDown) { _needMoveArr.Add(_arrSpriteIcon[_moveConfig, i]); } } } GameObject clonetemp = null; if (_arrSpriteIcon[_moveConfig, cloneidx]) { //_arrSpriteIcon[_moveConfig, cloneidx].GetComponent<BlockAni>()._curState = (BlockAni.BlockState.Move); clonetemp = Instantiate(_arrSpriteIcon[_moveConfig, cloneidx]); BlockAni clonecs = clonetemp.GetComponent <BlockAni>(); BlockAni clonecs2 = _arrSpriteIcon[_moveConfig, cloneidx].GetComponent <BlockAni>(); clonecs._picidx = clonecs2._picidx; clonetemp.GetComponent <BlockAni>().setPosByArrIdx(_moveConfig, totalnum); _needMoveArr.Add(clonetemp); _mainGame.GetComponent <MainGame>()._arrAllBlock.Add(clonetemp); clonetemp.GetComponent <BlockAni>()._lastPos = (new Vector2(_moveConfig, spidx)); _needDownGameObject = clonetemp; } _needDelGameObject = _arrSpriteIcon[_moveConfig, cloneidx]; for (int i = 0; i < totalnum - 1; i++) { _arrSpriteIcon[_moveConfig, i] = _arrSpriteIcon[_moveConfig, i + 1]; if (_arrSpriteIcon[_moveConfig, i] != null) { _arrSpriteIcon[_moveConfig, i].GetComponent <BlockAni>()._lastPos = (new Vector2(_moveConfig, i)); } } _arrSpriteIcon[_moveConfig, spidx] = clonetemp; } else if (_curInputEvent == GameInputEvent.MoveUp) { _mainGame.GetComponent <MainGame>().startProtect(); _speed.y = _speedValue; _speed.x = 0.0f; int totalnum = GameConfig.GAMEROW; for (int i = 0; i < totalnum; i++) { if (_arrSpriteIcon[_moveConfig, i] != null) { if (_arrSpriteIcon[_moveConfig, i].GetComponent <BlockAni>()._curState == BlockAni.BlockState.Stand || _arrSpriteIcon[_moveConfig, i].GetComponent <BlockAni>()._curState == BlockAni.BlockState.CountDown) { _needMoveArr.Add(_arrSpriteIcon[_moveConfig, i]); } } } _needDelGameObject = null; for (int i = totalnum - 1; i > 0; i--) { _arrSpriteIcon[_moveConfig, i] = _arrSpriteIcon[_moveConfig, i - 1]; if (_arrSpriteIcon[_moveConfig, i] != null) { _arrSpriteIcon[_moveConfig, i].GetComponent <BlockAni>()._lastPos = (new Vector2(_moveConfig, i)); } } _arrSpriteIcon[_moveConfig, 0] = null; } for (int i = 0; i < _needMoveArr.Count; i++) { BlockAni cs = _needMoveArr[i].GetComponent <BlockAni>(); if (cs._curState == BlockAni.BlockState.CountDown || cs._curState == BlockAni.BlockState.ShouldDel) { _mainGame.GetComponent <MainGame>().getWaitingStructById(cs._uniqueId).resetState(); _mainGame.GetComponent <MainGame>().removeWaitingStructById(cs._uniqueId); ComboMgr.getInstance().sendMessage(ComboMgr.ComboMessage.CANCLE_COUNT_DOWN); } if (_curInputEvent == GameInputEvent.MoveLeft || _curInputEvent == GameInputEvent.MoveRight) { _needMoveArr[i].GetComponent <BlockAni>()._curState = (BlockAni.BlockState.MoveLR); } else if (_curInputEvent == GameInputEvent.MoveUp || _curInputEvent == GameInputEvent.MoveDown) { _needMoveArr[i].GetComponent <BlockAni>()._curState = (BlockAni.BlockState.MoveUpDown); } } if (_curInputEvent == GameInputEvent.MoveLeft || _curInputEvent == GameInputEvent.MoveRight) { if (_needDelGameObject != null) { _needDelGameObject.GetComponent <BlockAni>()._curState = (BlockAni.BlockState.MoveLR); } } else if (_curInputEvent == GameInputEvent.MoveUp || _curInputEvent == GameInputEvent.MoveDown) { if (_needDelGameObject != null) { _needDelGameObject.GetComponent <BlockAni>()._curState = (BlockAni.BlockState.MoveUpDown); } } }