[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdegames/kpat
From:       Parker Coates <parker.coates () kdemail ! net>
Date:       2012-02-15 4:44:34
Message-ID: 20120215044434.B3BABAC894 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1280155 by coates:

Clean up Aces Up's click handling.

* Reimplement DealerScene::tryAutomaticMove() instead of adding a new
  handleCardClick slot.
* Add some missing runtime checks.
* Replace some redundant runtime checks with assertions.

 M  +21 -15    idiot.cpp  
 M  +1 -3      idiot.h  


--- trunk/KDE/kdegames/kpat/idiot.cpp #1280154:1280155
@@ -56,6 +56,7 @@
     talon->setSpread(0, 0);
     talon->setKeyboardSelectHint( KCardPile::NeverFocus );
     talon->setKeyboardDropHint( KCardPile::NeverFocus );
+    connect( talon, SIGNAL(clicked(KCard*)), this, SLOT(newCards()) );
 
     const qreal distx = 1.1;
 
@@ -79,7 +80,7 @@
     m_away->setKeyboardSelectHint(KCardPile::NeverFocus);
     m_away->setKeyboardDropHint(KCardPile::ForceFocusTop);
 
-    connect( this, SIGNAL(cardClicked(KCard*)), this, SLOT(handleCardClick(KCard*)) );
+    connect( this, SIGNAL(cardClicked(KCard*)), this, SLOT(tryAutomaticMove(KCard*)) );
 
     setActions(DealerScene::Hint | DealerScene::Demo | DealerScene::Deal);
     setSolver( new IdiotSolver(this ) );
@@ -112,7 +113,7 @@
     switch ( pile->pileRole() )
     {
     case PatPile::Foundation:
-        return canMoveAway( newCards.first() );
+        return true;
     case PatPile::Tableau:
         return oldCards.isEmpty() && newCards.size() == 1;
     case PatPile::Stock:
@@ -134,12 +135,10 @@
 
 bool Idiot::canMoveAway(const KCard * card) const
 {
-    if ( card->pile() == talon || card->pile() == m_away )
-        return false;
+    Q_ASSERT( card->pile() != talon );
+    Q_ASSERT( card->pile() != m_away );
+    Q_ASSERT( card == card->pile()->topCard() );
 
-    if ( card != card->pile()->topCard() )
-        return false;
-
     for ( int i = 0; i < 4; ++i )
     {
         KCard * c = m_play[i]->topCard();
@@ -157,16 +156,17 @@
 
 
 
-void Idiot::handleCardClick( KCard * card )
+bool Idiot::tryAutomaticMove( KCard * card )
 {
-    // Only the top card of a pile can be clicked.
-    if ( card != card->pile()->topCard())
-        return;
-
+    if ( !isCardAnimationRunning()
+         && card
+         && card->pile()
+         && card == card->pile()->topCard()
+         && card->pile() != talon
+         && card->pile() != m_away )
+    {
     KCardPile * destination = 0;
-    if ( card->pile() == talon )
-        drawDealRowOrRedeal();
-    else if ( canMoveAway( card) )
+        if ( canMoveAway( card ) )
         destination = m_away;
     else if ( m_play[0]->isEmpty() )
         destination = m_play[0];
@@ -178,9 +178,15 @@
         destination = m_play[3];
 
     if ( destination )
+        {
         moveCardToPile( card, destination, DURATION_MOVE );
+            return true;
 }
+    }
+    return false;
+}
 
+
 // The game is won when:
 //  1. all cards are dealt.
 //  2. all piles contain exactly one ace.
--- trunk/KDE/kdegames/kpat/idiot.h #1280154:1280155
@@ -57,10 +57,8 @@
 
 protected slots:
     virtual bool newCards();
+    virtual bool tryAutomaticMove( KCard * card );
 
-private slots:
-    void handleCardClick( KCard * card );
-
 private:
     void dealRow();
     bool canMoveAway(const KCard * card) const;
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic