7 #define TRACE(s) printf("%s(%i): %s",__FILE__,__LINE__,s)
10 extern TCHAR MsgWin
[128];
11 extern TCHAR MsgDeal
[128];
14 bool fGameStarted
= false;
18 TRACE("ENTER NewGame()\n");
23 //create a new card-stack
29 //deal to each row stack..
30 for(i
= 0; i
< NUM_ROW_STACKS
; i
++)
35 pRowStack
[i
]->SetFaceDirection(CS_FACE_DOWNUP
, i
);
37 for(j
= 0; j
<= i
; j
++)
39 temp
.Push(deck
.Pop());
42 pRowStack
[i
]->SetCardStack(temp
);
45 //put the other cards onto the deck
46 pDeck
->SetCardStack(deck
);
49 // For the 1-card-mode, all cards need to be completely overlapped
50 if(!(dwOptions
& OPTION_THREE_CARDS
))
51 pPile
->SetOffsets(0, 0);
56 TRACE("EXIT NewGame()\n");
60 // Now follow the stack callback functions. This is where we
61 // provide the game functionality and rules
65 // Can only drag face-up cards
67 bool CARDLIBPROC
RowStackDragProc(CardRegion
&stackobj
, int iNumDragCards
)
69 TRACE("ENTER RowStackDragProc()\n");
73 stackobj
.GetFaceDirection(&numfacedown
);
75 numcards
= stackobj
.NumCards();
77 TRACE("EXIT RowStackDragProc()\n");
78 if(iNumDragCards
<= numcards
-numfacedown
)
86 // Row a row-stack, we can only drop cards
87 // that are lower / different colour
89 bool CARDLIBPROC
RowStackDropProc(CardRegion
&stackobj
, CardStack
&dragcards
)
91 TRACE("ENTER RowStackDropProc()\n");
92 Card dragcard
= dragcards
[dragcards
.NumCards() - 1];
94 //if we are empty, can only drop a stack with a King at bottom
95 if(stackobj
.NumCards() == 0)
97 if(dragcard
.LoVal() != 13)
99 TRACE("EXIT RowStackDropProc(false)\n");
105 const CardStack
&mystack
= stackobj
.GetCardStack();
107 //can only drop if card is 1 less
108 if(mystack
[0].LoVal() != dragcard
.LoVal() + 1)
110 TRACE("EXIT RowStackDropProc(false)\n");
114 //can only drop if card is different colour
115 if( (mystack
[0].IsBlack() && !dragcard
.IsRed()) ||
116 (!mystack
[0].IsBlack() && dragcard
.IsRed()) )
118 TRACE("EXIT RowStackDropProc(false)\n");
125 TRACE("EXIT RowStackDropProc(true)\n");
130 // Can only drop a card onto a suit-stack if the
131 // card is 1 higher, and is the same suit
133 bool CanDrop(CardRegion
&stackobj
, Card card
)
135 TRACE("ENTER CanDrop()\n");
138 const CardStack
&cardstack
= stackobj
.GetCardStack();
140 if(cardstack
.NumCards() > 0)
142 if(card
.Suit() != cardstack
[0].Suit())
144 TRACE("EXIT CanDrop()\n");
148 topval
= cardstack
[0].LoVal();
156 if(card
.LoVal() != (topval
+ 1))
158 TRACE("EXIT CanDrop()\n");
162 TRACE("EXIT CanDrop()\n");
167 // Can only drop a card onto suit stack if it is same suit, and 1 higher
169 bool CARDLIBPROC
SuitStackDropProc(CardRegion
&stackobj
, CardStack
&dragcards
)
171 TRACE("ENTER SuitStackDropProc()\n");
172 //only drop 1 card at a time
173 if(dragcards
.NumCards() != 1)
175 TRACE("EXIT SuitStackDropProc()\n");
179 bool b
= CanDrop(stackobj
, dragcards
[0]);
180 TRACE("EXIT SuitStackDropProc()\n");
185 // Single-click on one of the row-stacks
186 // Turn the top-card over if they are all face-down
188 void CARDLIBPROC
RowStackClickProc(CardRegion
&stackobj
, int iNumClicked
)
190 TRACE("ENTER RowStackClickProc()\n");
193 stackobj
.GetFaceDirection(&numfacedown
);
195 //if all face-down, then make top card face-up
196 if(stackobj
.NumCards() == numfacedown
)
198 if(numfacedown
> 0) numfacedown
--;
199 stackobj
.SetFaceDirection(CS_FACE_DOWNUP
, numfacedown
);
202 TRACE("EXIT RowStackClickProc()\n");
206 // Find the suit-stack that can accept the specified card
208 CardRegion
*FindSuitStackFromCard(Card card
)
210 TRACE("ENTER FindSuitStackFromCard()\n");
211 for(int i
= 0; i
< 4; i
++)
213 if(CanDrop(*pSuitStack
[i
], card
))
215 TRACE("EXIT FindSuitStackFromCard()\n");
216 return pSuitStack
[i
];
220 TRACE("EXIT FindSuitStackFromCard()\n");
225 // What happens when we add a card to one of the suit stacks?
226 // Well, nothing (it is already added), but we need to
227 // check all four stacks (not just this one) to see if
228 // the game has finished.
230 void CARDLIBPROC
SuitStackAddProc(CardRegion
&stackobj
, const CardStack
&added
)
232 TRACE("ENTER SuitStackAddProc()\n");
233 bool fGameOver
= true;
235 for(int i
= 0; i
< 4; i
++)
237 if(pSuitStack
[i
]->NumCards() != 13)
246 MessageBox(SolWnd
, MsgWin
, szAppName
, MB_OK
| MB_ICONINFORMATION
);
248 for(int i
= 0; i
< 4; i
++)
250 pSuitStack
[i
]->Flash(11, 100);
253 if( IDYES
== MessageBox(SolWnd
, MsgDeal
, szAppName
, MB_YESNO
| MB_ICONQUESTION
) )
259 SolWnd
.EmptyStacks();
261 fGameStarted
= false;
265 TRACE("EXIT SuitStackAddProc()\n");
269 // Double-click on one of the row stacks
270 // The aim is to find a suit-stack to move the
271 // double-clicked card to.
273 void CARDLIBPROC
RowStackDblClickProc(CardRegion
&stackobj
, int iNumClicked
)
275 TRACE("ENTER RowStackDblClickProc()\n");
276 //can only move 1 card at a time
279 TRACE("EXIT RowStackDblClickProc()\n");
283 //find a suit-stack to move the card to...
284 const CardStack
&cardstack
= stackobj
.GetCardStack();
285 CardRegion
*pDest
= FindSuitStackFromCard(cardstack
[0]);
291 //stackobj.MoveCards(pDest, 1, true);
292 //use the SimulateDrag funcion, because we get the
293 //AddProc callbacks called for us on the destination stacks...
294 stackobj
.SimulateDrag(pDest
, 1, true);
296 TRACE("EXIT RowStackDblClickProc()\n");
300 // Face-up pile double-click
302 void CARDLIBPROC
PileDblClickProc(CardRegion
&stackobj
, int iNumClicked
)
304 TRACE("ENTER PileDblClickProc()\n");
305 RowStackDblClickProc(stackobj
, iNumClicked
);
306 TRACE("EXIT PileDblClickProc()\n");
310 // What happens when a card is removed from face-up pile?
312 void CARDLIBPROC
PileRemoveProc(CardRegion
&stackobj
, int iItems
)
314 TRACE("ENTER PileRemoveProc()\n");
315 //modify our "virtual" pile by removing the same card
316 //that was removed from the physical card stack
317 activepile
.Pop(iItems
);
319 //if there is just 1 card left, then modify the
320 //stack to contain ALL the face-up cards..the effect
321 //will be, the next time a card is dragged, all the
322 //previous card-triplets will be available underneath
323 if(stackobj
.NumCards() == 1)
325 stackobj
.SetOffsets(0,0);
326 stackobj
.SetCardStack(activepile
);
328 TRACE("EXIT PileRemoveProc()\n");
332 // Double-click on the deck
333 // Move 3 cards to the face-up pile
335 void CARDLIBPROC
DeckClickProc(CardRegion
&stackobj
, int iNumClicked
)
337 TRACE("ENTER DeckClickProc()\n");
338 CardStack cardstack
= stackobj
.GetCardStack();
339 CardStack pile
= pPile
->GetCardStack();
343 //reset the face-up pile to represent 3 cards
344 if(dwOptions
& OPTION_THREE_CARDS
)
345 pPile
->SetOffsets(CS_DEFXOFF
, 1);
347 if(cardstack
.NumCards() == 0)
351 activepile
.Reverse();
352 cardstack
.Push(activepile
);
357 int numcards
= min((dwOptions
& OPTION_THREE_CARDS
) ? 3 : 1, cardstack
.NumCards());
359 //make a "visible" copy of these cards
361 temp
= cardstack
.Pop(numcards
);
364 if(dwOptions
& OPTION_THREE_CARDS
)
369 //remove the top 3 from deck
370 activepile
.Push(temp
);
375 pDeck
->SetCardStack(cardstack
);
376 pPile
->SetCardStack(pile
);
379 TRACE("EXIT DeckClickProc()\n");