1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248
|
/*
* Copyright (C) 1997 Rodolfo Borges <barrett@labma.ufrj.br>
* Copyright (C) 1998-2009 Stephan Kulow <coolo@kde.org>
* Copyright (C) 2010 Parker Coates <coates@kde.org>
*
* License of original code:
* -------------------------------------------------------------------------
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose and without fee is hereby granted,
* provided that the above copyright notice appear in all copies and that
* both that copyright notice and this permission notice appear in
* supporting documentation.
*
* This file is provided AS IS with no warranties of any kind. The author
* shall have no liability with respect to the infringement of copyrights,
* trade secrets or any patents by this file or any part thereof. In no
* event will the author be liable for any lost revenue or profits or
* other special, indirect and consequential damages.
* -------------------------------------------------------------------------
*
* License of modifications/additions made after 2009-01-01:
* -------------------------------------------------------------------------
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* -------------------------------------------------------------------------
*/
#include "mod3.h"
#include "dealerinfo.h"
#include "patsolve/mod3solver.h"
#include <KLocale>
Mod3::Mod3( const DealerInfo * di )
: DealerScene( di )
{
}
void Mod3::initialize()
{
// Piles are placed very close together. Set layoutSpacing to 0 to prevent
// interference between them.
setLayoutSpacing(0.0);
const qreal dist_x = 1.114;
const qreal dist_y = 1.31;
const qreal bottomRowY = 3 * dist_y + 0.2;
const qreal rightColumX = 8 * dist_x + 0.8;
// This patience uses 2 deck of cards.
setDeckContents( 2 );
talon = new PatPile( this, 0, "talon" );
talon->setPileRole(PatPile::Stock);
talon->setLayoutPos(rightColumX, bottomRowY);
talon->setSpread(0, 0);
talon->setKeyboardSelectHint( KCardPile::NeverFocus );
talon->setKeyboardDropHint( KCardPile::NeverFocus );
connect( talon, SIGNAL(clicked(KCard*)), SLOT(drawDealRowOrRedeal()) );
aces = new PatPile( this, 50, "aces");
aces->setPileRole(PatPile::FoundationType1);
aces->setLayoutPos(rightColumX, 0.5);
aces->setBottomPadding( 2.5 );
aces->setKeyboardSelectHint( KCardPile::NeverFocus );
aces->setKeyboardDropHint( KCardPile::ForceFocusTop );
for ( int r = 0; r < 4; ++r )
{
for ( int c = 0; c < 8; ++c )
{
int pileIndex = r * 10 + c + 1;
QString objectName = QString( "stack%1_%2" ).arg( r ).arg( c );
stack[r][c] = new PatPile( this, pileIndex, objectName );
// The first 3 rows are the playing field, the fourth is the store.
if ( r < 3 )
{
stack[r][c]->setLayoutPos( dist_x * c, dist_y * r );
// Very tight spread makes it easy to quickly tell number of
// cards in each pile and we don't care about the cards beneath.
stack[r][c]->setSpread( 0, 0.08 );
stack[r][c]->setBottomPadding( 0.23 );
}
else
{
stack[r][c]->setLayoutPos( dist_x * c, bottomRowY );
stack[r][c]->setBottomPadding( 0.8 );
}
stack[r][c]->setPileRole( r == 0 ? PatPile::FoundationType2
: r == 1 ? PatPile::FoundationType3
: r == 2 ? PatPile::FoundationType4
: PatPile::Tableau );
stack[r][c]->setHeightPolicy( KCardPile::GrowDown );
stack[r][c]->setKeyboardSelectHint( KCardPile::AutoFocusTop );
stack[r][c]->setKeyboardDropHint( KCardPile::AutoFocusTop );
}
}
setActions(DealerScene::Hint | DealerScene::Demo | DealerScene::Deal);
setSolver( new Mod3Solver( this ) );
}
bool mod3CheckAdd(int baseRank, const QList<KCard*> & oldCards, const QList<KCard*> & newCards)
{
if (oldCards.isEmpty())
return newCards.first()->rank() == baseRank;
else
return oldCards.first()->rank() == baseRank
&& newCards.first()->suit() == oldCards.last()->suit()
&& newCards.first()->rank() == oldCards.last()->rank() + 3;
}
bool Mod3::checkAdd(const PatPile * pile, const QList<KCard*> & oldCards, const QList<KCard*> & newCards) const
{
switch (pile->pileRole())
{
case PatPile::FoundationType1:
return newCards.size() == 1 && newCards.first()->rank() == KCardDeck::Ace;
case PatPile::FoundationType2:
return mod3CheckAdd(KCardDeck::Two, oldCards, newCards);
case PatPile::FoundationType3:
return mod3CheckAdd(KCardDeck::Three, oldCards, newCards);
case PatPile::FoundationType4:
return mod3CheckAdd(KCardDeck::Four, oldCards, newCards);
case PatPile::Tableau:
return oldCards.isEmpty();
case PatPile::Stock:
default:
return false;
}
}
bool Mod3::checkRemove(const PatPile * pile, const QList<KCard*> & cards) const
{
switch (pile->pileRole())
{
case PatPile::FoundationType2:
case PatPile::FoundationType3:
case PatPile::FoundationType4:
case PatPile::Tableau:
return cards.first() == pile->topCard();
case PatPile::FoundationType1:
case PatPile::Stock:
default:
return false;
}
}
void Mod3::cardsMoved( const QList<KCard*> & cards, KCardPile * oldPile, KCardPile * newPile )
{
if ( oldPile->isEmpty() && !talon->isEmpty() )
{
PatPile * p = dynamic_cast<PatPile*>( oldPile );
if ( p && p->pileRole() == PatPile::Tableau )
flipCardToPile( talon->topCard(), oldPile, DURATION_MOVE );
}
DealerScene::cardsMoved( cards, oldPile, newPile );
}
void Mod3::restart( const QList<KCard*> & cards )
{
foreach ( KCard * c, cards )
{
c->setPos( talon->pos() );
c->setFaceUp( false );
talon->add( c );
}
for ( int r = 0; r < 4; r++ )
{
for ( int c = 0; c < 8; ++c )
{
KCard * card = talon->topCard();
card->setFaceUp( true );
// moveCardToPileAtSpeed( card, stack[r][c], DEAL_SPEED );
addCardForDeal( stack[r][c], card, true, talon->pos() );
// Fudge the z values to keep cards from popping through one another.
card->setZValue( card->zValue() + ((4 - r) * (4 - r)) + ((8 - c) * (8 - c)) );
}
}
startDealAnimation();
emit newCardsPossible(true);
}
bool Mod3::newCards()
{
if ( talon->isEmpty() )
return false;
for ( int c = 0; c < 8; ++c )
{
if ( talon->isEmpty() )
break;
flipCardToPileAtSpeed( talon->topCard(), stack[3][c], DEAL_SPEED * 2 );
}
if (talon->isEmpty())
emit newCardsPossible(false);
return true;
}
void Mod3::setGameState( const QString & state )
{
Q_UNUSED( state );
emit newCardsPossible(!talon->isEmpty());
}
static class Mod3DealerInfo : public DealerInfo
{
public:
Mod3DealerInfo()
: DealerInfo(I18N_NOOP("Mod3"), Mod3Id)
{}
virtual DealerScene *createGame() const
{
return new Mod3( this );
}
} mod3DealerInfo;
#include "mod3.moc"
|