void GameController::CoordinateReleased() { for(int i=0;i<getLevel();++i) for(int j=0;j<getLevel();++j) setBlockColor(QPoint(i,j),GameData::BgColor); for(int i=0;i<getColorNumber()*2;++i) setBlockColor(gameSetting->Points[i],GameData::ColorSet[i/2]); for(int i=0;i<pipeManager->size();++i) { Pipe* pipe = pipeManager->at(i); if(pipeManager->currentPipe!=pipe) { while(!pipe->empty()) { QPoint _coordinate(pipe->back()); STATE _state = getBlockState(_coordinate); if((_state&WAY)==0||(_state&BREAK)!=0||(_state&CURRENT)!=0) pipe->pop_back(); else break; } } for(int j=0;j<pipe->size();++j) setBlockColor(pipe->at(j),pipe->Color); } for(int i=0;i<this->getLevel();++i) for(int j=0;j<this->getLevel();++j) setBlockState(QPoint(i,j),~(CURRENT|BREAK)); ++gameSetting->moves; emit UpdatePipeDisplay(); emit UpdateBlockDisplay(); if(CheckWin()) emit CompleteGame(); }
void GameController::CoordinateSelected(const QPoint &_coordinate) { this->pipeManager->currentPipe = this->pipeManager->getPipe(this->getBlockColor(_coordinate)); Pipe* pipe = pipeManager->currentPipe; while(!pipe->empty() && (pipe->back()!=_coordinate||(getBlockState(_coordinate)&ORIGIN)!=0)) { setBlockState(pipe->back(),~(WAY|CURRENT)); pipe->pop_back(); } if(pipe->empty()) { setBlockState(_coordinate,WAY|CURRENT); pipe->push_back(_coordinate); } for(int i=0;i<pipe->size();++i) setBlockState(pipe->at(i),CURRENT); emit UpdatePipeDisplay(); }
bool GameController::CheckWin() { for(int i=0;i<pipeManager->size();++i) { Pipe* pipe = pipeManager->at(i); if(pipe->size()<2) return false; if((getBlockState(pipe->back())&ORIGIN)==0) return false; } for(int i=0;i<getLevel();++i) for(int j=0;j<getLevel();++j) if((getBlockState(QPoint(i,j))&WAY)==0) return false; if(gameSetting->best<=0 || gameSetting->moves<gameSetting->best) gameSetting->setBest(gameSetting->moves); return true; }
void GameController::GameStateRecalculate() { int pipeCompleteCount = 0; for(int i=0;i<getLevel();++i) for(int j=0;j<getLevel();++j) if((blockstate[i][j]&WAY)!=0) ++pipeCompleteCount; gameSetting->pipeFilled = floor(pipeCompleteCount*100/getLevel()/getLevel()); int pipeLinkCount = 0; for(int i=0;i<pipeManager->size();++i) { Pipe* pipe = pipeManager->at(i); if(pipe->size()<2) continue; if((getBlockState(pipe->back())&ORIGIN)==0) continue; ++pipeLinkCount; } gameSetting->currentflows = pipeLinkCount; }