// 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; }
// remove tiles and fill the game fields until only maximum // two same tiles are next to each other void GameField::cascade(void) { // print(); ScoredTileArray tArray; while ( findSameTiles(tArray) ) { // remove tiles removeTiles(tArray); // first let all existing tiles fall to the ground fallTilesToGround(false); // and fill with new ones fillEmptyTiles(); // clear array again tArray.clear(); } }
// remove same tiles on field and give points to player const bool Game::cascade(const bool contest) { ScoredTileArray tArray; bool ok = true; // flag if first loop bool first = true; while ( m_field.findSameTiles(tArray) ) { #ifdef DEBUG // print game field if (!first) { std::cout << "Game::cascade() info: Intermediate game field" << std::endl; m_field.print(); } #endif // remove tiles m_field.removeTiles(tArray); // add points for player m_player[m_currentPlayer].addPoints(tArray); // calculate damage for opponent unsigned int damage = m_player[m_currentPlayer].getOpponentDamage(); #ifdef DEBUG if ( damage > 0 ) { std::cout << "Game::cascade() info: opponent looses " << damage << " life." << std::endl; } #endif m_player[(m_currentPlayer+1)%2].looseLife( damage ); // first let all existing tiles fall to the ground if ( !m_field.fallTilesToGround(contest) ) { if ( !contest ) { // we need some random tiles m_field.fillEmptyTiles(); } else { // we do not have any more tiles for contest ok = false; break; } } // clear array again tArray.clear(); first = false; } return ok; }