Beispiel #1
0
// remove lower line in game field    
// return true if there are still tiles that can be dropped down
// in contest
const bool GameField::removeLowerLine(const bool contest)
{
#ifdef DEBUG
    std::cout << "GameField::removeLowerLine("
              << contest
              << ")" << std::endl;
#endif

    bool ok = false;
              
    // create array with lower line
    ScoredTileArray tArray;
    ScoredTile sTile( FieldPos(0, 0), 10,
                      ScoredTile::FIELDDIRECTION_RIGHT,
                      m_field[0][0], 0 );
    tArray.push_back(sTile);
    
    // remove tiles
    removeTiles(tArray);
    
    // let all existing tiles fall to the ground
    ok = fallTilesToGround(contest);

    // and fill with new ones
    fillEmptyTiles();
        
    // clear array again
    tArray.clear();
            
    return ok;
}
Beispiel #2
0
void KLinesScene::startNewGame()
{
    if(m_animator->isAnimating())
        return;

    // reset all vars
    m_selPos = FieldPos();
    m_numFreeCells = FIELD_SIZE*FIELD_SIZE;
    m_score = 0;
    m_bonusScore = 0;
    m_placeBalls = true;
    m_gameOver = false;
    m_itemsToDelete.clear();
    m_nextColors.clear();
    m_focusItem->setPos(0, 0);
    m_focusItem->hide();

    m_popupItem->forceHide();

    // remove all ball items from the scene leaving other items untouched
    QList<QGraphicsItem*> itemlist = items();
    foreach( QGraphicsItem* item, itemlist )
    {
        BallItem* ball = qgraphicsitem_cast<BallItem*>(item);
        if( ball )
        {
            removeItem(item);
            delete item;
        }
    }
Beispiel #3
0
// search for equal tiles in columns
// return true if something has been found
const bool GameField::findSameTilesInColumns(ScoredTileArray& tArray) const
{
    bool found = false;
            
    // we will go through each column
    for ( unsigned int i = 0; i < FIELD_WIDTH; i++ )
    {
        // reset length
        unsigned int length = 0;
        unsigned int bombValue = 0;
        
        for ( unsigned int j = 0; j < FIELD_HEIGHT; j++ )
        {
            if ( 0 == j || m_field[i][j] == m_field[i][j-1] )
            {
                // same tile as before or new start tile
                length++;
                
                // check if bomb and add bomb value
                if ( m_field[i][j].isBomb() )
                {
                    bombValue += m_field[i][j].getBombValue();
                }
                
                // if the last tile in this column
                // we must check the length
                if ( FIELD_HEIGHT-1 == j && length >= 3 )
                {
                    // only store tiles if length is >= 3
                    ScoredTile sTile( FieldPos(i, j-length+1), length,
                                      ScoredTile::FIELDDIRECTION_UP,
                                      m_field[i][j], bombValue );
                    tArray.push_back(sTile);
                   
                    found = true;
                    
                    //std::cout << "GameField::findSameTilesInColumns1() " 
                              //<< i << " "  
                              //<< j-length+1 << " " 
                              //<< length << " " 
                              //<< (char)m_field[i][j].getType() << " "
                              //<< bombValue
                              //<< std::endl;
                }                
            }
            else
            {
                // new tile here
                if ( length >= 3 )
                {
                    // only store tiles if length is >= 3
                    ScoredTile sTile( FieldPos(i, j-length), length,
                                      ScoredTile::FIELDDIRECTION_UP,
                                      m_field[i][j-1], bombValue );
                    tArray.push_back(sTile);
                    
                    found = true;

                    //std::cout << "GameField::findSameTilesInColumns2() " 
                              //<< i << " "  
                              //<< j-length << " " 
                              //<< length << " " 
                              //<< (char)m_field[i][j-1].getType() << " "
                              //<< bombValue
                              //<< std::endl;
                }

                // set new length
                length = 1;
                bombValue = 0;

                // check if bomb and add bomb value
                if ( m_field[i][j].isBomb() )
                {
                    bombValue += m_field[i][j].getBombValue();
                }
            }
        }
    }    
    
    return found;
}