From c90c389a8a8d9d8661e9772ec4144c5cf2039f23 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdegames@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- klickety/board.cpp | 163 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 163 insertions(+) create mode 100644 klickety/board.cpp (limited to 'klickety/board.cpp') diff --git a/klickety/board.cpp b/klickety/board.cpp new file mode 100644 index 00000000..92969d6e --- /dev/null +++ b/klickety/board.cpp @@ -0,0 +1,163 @@ +#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; +} -- cgit v1.2.1