예제 #1
0
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();
}
예제 #2
0
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();
}
예제 #3
0
void GameController::CoordinateChanged(const QPoint &_coordinate)
{

    if(this->pipeManager->currentPipe==0)
        return;
    QPoint lastcoordinate = this->pipeManager->currentPipe->back();
    QColor _coordinateColor = getBlockColor(_coordinate);
    STATE _coordinateState = getBlockState(_coordinate);
    int distance = Distance(lastcoordinate,_coordinate);
    if((_coordinateState&CURRENT)==0&&(getBlockState(lastcoordinate)&ORIGIN)!=0&&getBlockColor(lastcoordinate)==this->pipeManager->currentPipe->Color&&this->pipeManager->currentPipe->size()>1)
        return;
    if(distance!=1)
    {
        if(distance<=5&&(_coordinateState&ORIGIN)==0)
            AutoSearchPath(_coordinate);
        return;
    }
    if((_coordinateState&WAY)==0)
    {
        if((_coordinateState&ORIGIN)==0)
        {
            setBlockState(_coordinate,WAY|CURRENT);
            pipeManager->currentPipe->push_back(_coordinate);
            emit ForwardPipe();
            emit UpdatePipeDisplay();
        }
        else
        {
            if(_coordinateColor==pipeManager->currentPipe->Color)
            {
                setBlockState(_coordinate,WAY|CURRENT);
                pipeManager->currentPipe->push_back(_coordinate);
                emit CompletePipe(pipeManager->currentPipe);
                emit UpdatePipeDisplay();
            }
        }
    }
    else
    {
        if((_coordinateState&CURRENT)!=0)
        {
            while(pipeManager->currentPipe->back()!=_coordinate)
            {
                QPoint backpoint = pipeManager->currentPipe->back();
                QColor backpointColor = getBlockColor(backpoint);
                setBlockState(backpoint,~CURRENT);
                if(backpointColor==GameData::BgColor || backpointColor==pipeManager->currentPipe->Color)
                    setBlockState(backpoint,~WAY);
                else
                {
                    setBlockState(backpoint,~BREAK);
                    Pipe* pipe = pipeManager->getPipe(backpointColor);
                    bool unable = false;
                    for(int i=0;i<pipe->size();++i)
                    {
                        STATE _state = getBlockState(pipe->at(i));
                        if((_state&BREAK)!=0)
                            unable = true;
                        if(unable && (_state&BREAK)==0)
                            setBlockState(pipe->at(i),~WAY);
                        else
                            setBlockState(pipe->at(i),WAY);
                    }
                }
                pipeManager->currentPipe->pop_back();
            }
            emit BackwardPipe();
            emit UpdatePipeDisplay();
        }
        else
        {
            if((_coordinateState&ORIGIN)!=0)
                return;
            Pipe* pipe = pipeManager->getPipe(_coordinateColor);
            setBlockState(_coordinate,WAY|CURRENT|BREAK);
            pipeManager->currentPipe->push_back(_coordinate);
            bool unable = false;
            for(int i=0;i<pipe->size();++i)
            {
                STATE _state = getBlockState(pipe->at(i));
                if((_state&BREAK)!=0)
                    unable = true;
                if(unable && (_state&BREAK)==0)
                    setBlockState(pipe->at(i),~WAY);
                else
                    setBlockState(pipe->at(i),WAY);
            }
            emit BreakPipe(pipe);
            emit UpdatePipeDisplay();
        }
    }
}