File indexing completed on 2024-05-12 08:00:36
0001 /* 0002 * Copyright (C) 2000-2009 Stephan Kulow <coolo@kde.org> 0003 * Copyright (C) 2010 Parker Coates <coates@kde.org> 0004 * 0005 * License of original code: 0006 * ------------------------------------------------------------------------- 0007 * Permission to use, copy, modify, and distribute this software and its 0008 * documentation for any purpose and without fee is hereby granted, 0009 * provided that the above copyright notice appear in all copies and that 0010 * both that copyright notice and this permission notice appear in 0011 * supporting documentation. 0012 * 0013 * This file is provided AS IS with no warranties of any kind. The author 0014 * shall have no liability with respect to the infringement of copyrights, 0015 * trade secrets or any patents by this file or any part thereof. In no 0016 * event will the author be liable for any lost revenue or profits or 0017 * other special, indirect and consequential damages. 0018 * ------------------------------------------------------------------------- 0019 * 0020 * License of modifications/additions made after 2009-01-01: 0021 * ------------------------------------------------------------------------- 0022 * This program is free software; you can redistribute it and/or 0023 * modify it under the terms of the GNU General Public License as 0024 * published by the Free Software Foundation; either version 2 of 0025 * the License, or (at your option) any later version. 0026 * 0027 * This program is distributed in the hope that it will be useful, 0028 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0029 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0030 * GNU General Public License for more details. 0031 * 0032 * You should have received a copy of the GNU General Public License 0033 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0034 * ------------------------------------------------------------------------- 0035 */ 0036 0037 #include "yukon.h" 0038 0039 // own 0040 #include "dealerinfo.h" 0041 #include "patsolve/yukonsolver.h" 0042 #include "pileutils.h" 0043 // KF 0044 #include <KLocalizedString> 0045 0046 Yukon::Yukon(const DealerInfo *di) 0047 : DealerScene(di) 0048 { 0049 } 0050 0051 void Yukon::initialize() 0052 { 0053 const qreal dist_x = 1.11; 0054 const qreal dist_y = 1.11; 0055 0056 setDeckContents(); 0057 0058 for (int i = 0; i < 4; ++i) { 0059 target[i] = new PatPile(this, i + 1, QStringLiteral("target%1").arg(i)); 0060 target[i]->setPileRole(PatPile::Foundation); 0061 target[i]->setLayoutPos(0.11 + 7 * dist_x, dist_y * i); 0062 target[i]->setKeyboardSelectHint(KCardPile::NeverFocus); 0063 target[i]->setKeyboardDropHint(KCardPile::ForceFocusTop); 0064 } 0065 0066 for (int i = 0; i < 7; ++i) { 0067 store[i] = new PatPile(this, 5 + i, QStringLiteral("store%1").arg(i)); 0068 store[i]->setPileRole(PatPile::Tableau); 0069 store[i]->setLayoutPos(dist_x * i, 0); 0070 store[i]->setAutoTurnTop(true); 0071 store[i]->setBottomPadding(3 * dist_y); 0072 store[i]->setHeightPolicy(KCardPile::GrowDown); 0073 store[i]->setKeyboardSelectHint(KCardPile::FreeFocus); 0074 store[i]->setKeyboardDropHint(KCardPile::AutoFocusTop); 0075 } 0076 0077 setActions(DealerScene::Hint | DealerScene::Demo); 0078 setSolver(new YukonSolver(this)); 0079 setNeededFutureMoves(10); // it's a bit hard to judge as there are so many nonsense moves 0080 } 0081 0082 bool Yukon::checkAdd(const PatPile *pile, const QList<KCard *> &oldCards, const QList<KCard *> &newCards) const 0083 { 0084 if (pile->pileRole() == PatPile::Tableau) { 0085 if (oldCards.isEmpty()) 0086 return newCards.first()->rank() == KCardDeck::King; 0087 else 0088 return newCards.first()->rank() == oldCards.last()->rank() - 1 && newCards.first()->color() != oldCards.last()->color(); 0089 } else { 0090 return checkAddSameSuitAscendingFromAce(oldCards, newCards); 0091 } 0092 } 0093 0094 bool Yukon::checkRemove(const PatPile *pile, const QList<KCard *> &cards) const 0095 { 0096 return pile->pileRole() == PatPile::Tableau && cards.first()->isFaceUp(); 0097 } 0098 0099 void Yukon::restart(const QList<KCard *> &cards) 0100 { 0101 QList<KCard *> cardList = cards; 0102 0103 for (int round = 0; round < 11; ++round) { 0104 for (int j = 0; j < 7; ++j) { 0105 if ((j == 0 && round == 0) || (j && round < j + 5)) { 0106 QPointF initPos = store[j]->pos(); 0107 initPos.ry() += ((7 - j / 3.0) + round) * deck()->cardHeight(); 0108 addCardForDeal(store[j], cardList.takeLast(), (round >= j || j == 0), initPos); 0109 } 0110 } 0111 } 0112 0113 startDealAnimation(); 0114 } 0115 0116 static class YukonDealerInfo : public DealerInfo 0117 { 0118 public: 0119 YukonDealerInfo() 0120 : DealerInfo(kli18n("Yukon"), YukonId) 0121 { 0122 } 0123 0124 DealerScene *createGame() const override 0125 { 0126 return new Yukon(this); 0127 } 0128 } yukonDealerInfo; 0129 0130 #include "moc_yukon.cpp"