#include "board.h" #include "board.moc" #include "base/factory.h" using namespace KGrid2D; void KLBoard::contentsMouseReleaseEvent(QMouseEvent *e) { if ( e->button()!=LeftButton || blocked ) return; QCanvasItemList list = canvas()->collisions(e->pos()); if ( list.count()==0 ) return; QCanvasSprite *spr = static_cast(list.first()); Coord c = findSprite(spr); field.fill(0); addRemoved = findGroup(field, c); if ( addRemoved>=2 ) { if ( state!=Normal ) { state = Normal; emit firstBlockClicked(); } blocked = true; _beforeRemove(true); } } KLBoard::KLBoard(QWidget *parent) : BaseBoard(true, parent), field(matrix().width(), matrix().height()), empty(matrix().width()), blocked(false) {} void KLBoard::start(const GTInitData &data) { BaseBoard::start(data); updateScore(matrix().width() * matrix().height()); state = GameOver; sliding = false; blocked = false; for (uint i=0; isetValue(Piece::info().generateType(&randomSequence()), main); Coord c(i, j); setBlock(c, block); } computeInfos(); showBoard(true); } Coord KLBoard::findSprite(QCanvasSprite *spr) const { for (uint i=0; isprite()==spr ) return c; } Q_ASSERT(false); return Coord(); } bool KLBoard::toBeRemoved(const Coord &c) const { return ( field[c]==-1 ); } void KLBoard::remove() { BaseBoard::remove(); updateRemoved(nbRemoved() + addRemoved); updateScore(score() - addRemoved); } bool KLBoard::toFall(const Coord &c) const { Coord under(c.first, c.second-1); return ( matrix()[under]==0 ); } void KLBoard::computeInfos() { BaseBoard::computeInfos(); if ( graphic() ) computeNeighbours(); empty.fill(true); for (uint i=0; ibbi.nbFallStages); for (uint j=0; j heights(matrix().width()); for (uint i=1; iupdate(); if (final) computeInfos(); return final; } BaseBoard::AfterRemoveResult KLBoard::afterRemove(bool doAll, bool first) { AfterRemoveResult res = Done; // dummy default if (sliding) { res = (doSlide(doAll, loop==bfactory->bbi.nbFallStages+1, false) ? Done : NeedAfterRemove); if ( res==Done ) sliding = false; } else { res = BaseBoard::afterRemove(doAll, first); if ( res==Done ) { res = NeedAfterRemove; sliding = true; loop++; } } return res; } bool KLBoard::afterAfterRemove() { // check if there are remaining groups field.fill(0); QMemArray groups = findGroups(field, 2, true); blocked = false; return groups.size()!=0; }