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
|
#include "golf.h"
#include <klocale.h>
#include "deck.h"
#include <kdebug.h>
#include "cardmaps.h"
HorRightPile::HorRightPile( int _index, Dealer* parent)
: Pile(_index, parent)
{
}
QSize HorRightPile::cardOffset( bool _spread, bool, const Card *) const
{
if (_spread)
return QSize(+hspread(), 0);
return QSize(0, 0);
}
//-------------------------------------------------------------------------//
Golf::Golf( KMainWindow* parent, const char* _name)
: Dealer( parent, _name )
{
const int dist_x = cardMap::CARDX() * 11 / 10 + 1;
const int pile_dist = 10 + 3 * cardMap::CARDY();
deck = Deck::new_deck( this);
deck->move(10, pile_dist);
connect(deck, SIGNAL(clicked(Card*)), SLOT(deckClicked(Card*)));
for( int r = 0; r < 7; r++ ) {
stack[r]=new Pile(1+r, this);
stack[r]->move(10+r*dist_x,10);
stack[r]->setAddFlags( Pile::addSpread | Pile::disallow);
stack[r]->setCheckIndex( 1 );
}
waste=new HorRightPile(8,this);
waste->move(10 + cardMap::CARDX() * 5 / 4, pile_dist);
waste->setTarget(true);
waste->setCheckIndex( 0 );
waste->setAddFlags( Pile::addSpread);
setActions(Dealer::Hint | Dealer::Demo);
}
//-------------------------------------------------------------------------//
bool Golf::checkAdd( int checkIndex, const Pile *c1, const CardList& cl) const
{
if (checkIndex == 1)
return false;
Card *c2 = cl.first();
kdDebug(11111)<<"check add "<< c1->name()<<" " << c2->name() <<" "<<endl;
if ((c2->rank() != (c1->top()->rank()+1)) && (c2->rank() != (c1->top()->rank()-1)))
return false;
return true;
}
bool Golf::checkRemove( int checkIndex, const Pile *, const Card *c2) const
{
if (checkIndex == 0)
return false;
return (c2 == c2->source()->top());
}
//-------------------------------------------------------------------------//
void Golf::restart()
{
deck->collectAndShuffle();
deal();
}
void Golf::deckClicked(Card *)
{
if (deck->isEmpty()) {
return;
}
Card *c = deck->nextCard();
waste->add(c, true, true);
int x = int(c->x());
int y = int(c->y());
c->move(deck->x(), deck->y());
c->flipTo(x, y, 8);
}
//-------------------------------------------------------------------------//
void Golf::deal()
{
for(int r=0;r<7;r++)
{
for(int i=0;i<5;i++)
{
stack[r]->add(deck->nextCard(),false,true);
}
}
waste->add(deck->nextCard(),false,false);
}
Card *Golf::demoNewCards()
{
deckClicked(0);
return waste->top();
}
bool Golf::cardClicked(Card *c)
{
if (c->source()->checkIndex() !=1) {
return Dealer::cardClicked(c);
}
if (c != c->source()->top())
return false;
Pile*p=findTarget(c);
if (p)
{
CardList empty;
empty.append(c);
c->source()->moveCards(empty, p);
canvas()->update();
return true;
}
return false;
}
bool Golf::isGameLost() const
{
if( !deck->isEmpty())
return false;
bool onecard = false;
for( int r = 0; r < 7; r++ ) {
if( !stack[r]->isEmpty()){
onecard = true;
CardList stackTops;
stackTops.append(stack[r]->top());
if(this->checkAdd(0,waste,stackTops))
return false;
}
}
return onecard;
}
static class LocalDealerInfo13 : public DealerInfo
{
public:
LocalDealerInfo13() : DealerInfo(I18N_NOOP("Go&lf"), 12) {}
virtual Dealer *createGame(KMainWindow *parent) { return new Golf(parent); }
} ldi13;
//-------------------------------------------------------------------------//
#include"golf.moc"
//-------------------------------------------------------------------------//
|