1 | /* |
2 | * Copyright (C) 2000-2009 Stephan Kulow <coolo@kde.org> |
3 | * Copyright (C) 2010 Parker Coates <coates@kde.org> |
4 | * |
5 | * License of original code: |
6 | * ------------------------------------------------------------------------- |
7 | * Permission to use, copy, modify, and distribute this software and its |
8 | * documentation for any purpose and without fee is hereby granted, |
9 | * provided that the above copyright notice appear in all copies and that |
10 | * both that copyright notice and this permission notice appear in |
11 | * supporting documentation. |
12 | * |
13 | * This file is provided AS IS with no warranties of any kind. The author |
14 | * shall have no liability with respect to the infringement of copyrights, |
15 | * trade secrets or any patents by this file or any part thereof. In no |
16 | * event will the author be liable for any lost revenue or profits or |
17 | * other special, indirect and consequential damages. |
18 | * ------------------------------------------------------------------------- |
19 | * |
20 | * License of modifications/additions made after 2009-01-01: |
21 | * ------------------------------------------------------------------------- |
22 | * This program is free software; you can redistribute it and/or |
23 | * modify it under the terms of the GNU General Public License as |
24 | * published by the Free Software Foundation; either version 2 of |
25 | * the License, or (at your option) any later version. |
26 | * |
27 | * This program is distributed in the hope that it will be useful, |
28 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
29 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
30 | * GNU General Public License for more details. |
31 | * |
32 | * You should have received a copy of the GNU General Public License |
33 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
34 | * ------------------------------------------------------------------------- |
35 | */ |
36 | |
37 | #include "yukon.h" |
38 | |
39 | #include "dealerinfo.h" |
40 | #include "pileutils.h" |
41 | #include "patsolve/yukonsolver.h" |
42 | |
43 | #include <KLocale> |
44 | |
45 | |
46 | Yukon::Yukon( const DealerInfo * di ) |
47 | : DealerScene( di ) |
48 | { |
49 | } |
50 | |
51 | |
52 | void Yukon::initialize() |
53 | { |
54 | const qreal dist_x = 1.11; |
55 | const qreal dist_y = 1.11; |
56 | |
57 | setDeckContents(); |
58 | |
59 | for ( int i = 0; i < 4; ++i ) |
60 | { |
61 | target[i] = new PatPile( this, i + 1, QString("target%1" ).arg(i) ); |
62 | target[i]->setPileRole(PatPile::Foundation); |
63 | target[i]->setLayoutPos(0.11+7*dist_x, dist_y *i); |
64 | target[i]->setKeyboardSelectHint( KCardPile::NeverFocus ); |
65 | target[i]->setKeyboardDropHint( KCardPile::ForceFocusTop ); |
66 | } |
67 | |
68 | for ( int i = 0; i < 7; ++i ) |
69 | { |
70 | store[i] = new PatPile( this, 5 + i, QString("store%1" ).arg(i) ); |
71 | store[i]->setPileRole(PatPile::Tableau); |
72 | store[i]->setLayoutPos(dist_x*i, 0); |
73 | store[i]->setAutoTurnTop(true); |
74 | store[i]->setBottomPadding( 3 * dist_y ); |
75 | store[i]->setHeightPolicy( KCardPile::GrowDown ); |
76 | store[i]->setKeyboardSelectHint( KCardPile::FreeFocus ); |
77 | store[i]->setKeyboardDropHint( KCardPile::AutoFocusTop ); |
78 | } |
79 | |
80 | setActions(DealerScene::Hint | DealerScene::Demo); |
81 | setSolver( new YukonSolver( this ) ); |
82 | setNeededFutureMoves( 10 ); // it's a bit hard to judge as there are so many nonsense moves |
83 | } |
84 | |
85 | bool Yukon::checkAdd(const PatPile * pile, const QList<KCard*> & oldCards, const QList<KCard*> & newCards) const |
86 | { |
87 | if (pile->pileRole() == PatPile::Tableau) |
88 | { |
89 | if (oldCards.isEmpty()) |
90 | return newCards.first()->rank() == KCardDeck::King; |
91 | else |
92 | return newCards.first()->rank() == oldCards.last()->rank() - 1 |
93 | && newCards.first()->color() != oldCards.last()->color(); |
94 | } |
95 | else |
96 | { |
97 | return checkAddSameSuitAscendingFromAce(oldCards, newCards); |
98 | } |
99 | } |
100 | |
101 | bool Yukon::checkRemove(const PatPile * pile, const QList<KCard*> & cards) const |
102 | { |
103 | return pile->pileRole() == PatPile::Tableau && cards.first()->isFaceUp(); |
104 | } |
105 | |
106 | void Yukon::restart( const QList<KCard*> & cards ) |
107 | { |
108 | QList<KCard*> cardList = cards; |
109 | |
110 | for ( int round = 0; round < 11; ++round ) |
111 | { |
112 | for ( int j = 0; j < 7; ++j ) |
113 | { |
114 | if ( ( j == 0 && round == 0 ) || ( j && round < j + 5 ) ) |
115 | { |
116 | QPointF initPos = store[j]->pos(); |
117 | initPos.ry() += ((7 - j / 3.0) + round) * deck()->cardHeight(); |
118 | addCardForDeal( store[j], cardList.takeLast(), (round >= j || j == 0), initPos ); |
119 | } |
120 | } |
121 | } |
122 | |
123 | startDealAnimation(); |
124 | } |
125 | |
126 | |
127 | |
128 | static class YukonDealerInfo : public DealerInfo |
129 | { |
130 | public: |
131 | YukonDealerInfo() |
132 | : DealerInfo(I18N_NOOP("Yukon" ), YukonId ) |
133 | {} |
134 | |
135 | virtual DealerScene *createGame() const |
136 | { |
137 | return new Yukon( this ); |
138 | } |
139 | } yukonDealerInfo; |
140 | |
141 | |
142 | #include "yukon.moc" |
143 | |