6 #define TRACE(s) printf("%s(%i): %s",__FILE__,__LINE__,s)
9 extern TCHAR MsgWin
[128];
10 extern TCHAR MsgDeal
[128];
14 bool fGameStarted
= false;
18 TRACE("ENTER NewGame()\n");
21 if (GetScoreMode() == SCORE_VEGAS
)
23 if ((dwOptions
& OPTION_KEEP_SCORE
) && (dwPrevMode
== SCORE_VEGAS
))
28 if (dwOptions
& OPTION_THREE_CARDS
)
36 if (dwOptions
& OPTION_THREE_CARDS
)
50 //create a new card-stack
56 //deal to each row stack..
57 for(i
= 0; i
< NUM_ROW_STACKS
; i
++)
62 pRowStack
[i
]->SetFaceDirection(CS_FACE_DOWNUP
, i
);
64 for(j
= 0; j
<= i
; j
++)
66 temp
.Push(deck
.Pop());
69 pRowStack
[i
]->SetCardStack(temp
);
72 //put the other cards onto the deck
73 pDeck
->SetCardStack(deck
);
76 // For the 1-card-mode, all cards need to be completely overlapped
77 if(!(dwOptions
& OPTION_THREE_CARDS
))
78 pPile
->SetOffsets(0, 0);
84 dwPrevMode
= GetScoreMode();
88 TRACE("EXIT NewGame()\n");
93 // Now follow the stack callback functions. This is where we
94 // provide the game functionality and rules
98 // Can only drag face-up cards
100 bool CARDLIBPROC
RowStackDragProc(CardRegion
&stackobj
, int iNumDragCards
)
102 TRACE("ENTER RowStackDragProc()\n");
108 stackobj
.GetFaceDirection(&numfacedown
);
110 numcards
= stackobj
.NumCards();
112 TRACE("EXIT RowStackDragProc()\n");
113 if(iNumDragCards
<= numcards
-numfacedown
)
121 // Row a row-stack, we can only drop cards
122 // that are lower / different colour
124 bool CARDLIBPROC
RowStackDropProc(CardRegion
&stackobj
, CardStack
&dragcards
)
126 TRACE("ENTER RowStackDropProc()\n");
127 Card dragcard
= dragcards
[dragcards
.NumCards() - 1];
131 //if we are empty, can only drop a stack with a King at bottom
132 if(stackobj
.NumCards() == 0)
134 if(dragcard
.LoVal() != 13)
136 TRACE("EXIT RowStackDropProc(false)\n");
142 const CardStack
&mystack
= stackobj
.GetCardStack();
144 //can only drop if card is 1 less
145 if(mystack
[0].LoVal() != dragcard
.LoVal() + 1)
147 TRACE("EXIT RowStackDropProc(false)\n");
151 //can only drop if card is different colour
152 if( (mystack
[0].IsBlack() && !dragcard
.IsRed()) ||
153 (!mystack
[0].IsBlack() && dragcard
.IsRed()) )
155 TRACE("EXIT RowStackDropProc(false)\n");
162 if (LastId
== PILE_ID
)
164 if (GetScoreMode() == SCORE_STD
)
169 else if ((LastId
>= SUIT_ID
) && (LastId
<= SUIT_ID
+ 3))
171 if (GetScoreMode() == SCORE_STD
)
173 lScore
= lScore
>= 15 ? lScore
- 15 : 0;
175 else if (GetScoreMode() == SCORE_VEGAS
)
177 lScore
= lScore
>= -47 ? lScore
- 5 : -52;
183 TRACE("EXIT RowStackDropProc(true)\n");
188 // Can only drop a card onto a suit-stack if the
189 // card is 1 higher, and is the same suit
191 bool CanDrop(CardRegion
&stackobj
, Card card
)
193 TRACE("ENTER CanDrop()\n");
196 const CardStack
&cardstack
= stackobj
.GetCardStack();
200 if(cardstack
.NumCards() > 0)
202 if(card
.Suit() != cardstack
[0].Suit())
204 TRACE("EXIT CanDrop()\n");
208 topval
= cardstack
[0].LoVal();
216 if(card
.LoVal() != (topval
+ 1))
218 TRACE("EXIT CanDrop()\n");
222 TRACE("EXIT CanDrop()\n");
227 // Can only drop a card onto suit stack if it is same suit, and 1 higher
229 bool CARDLIBPROC
SuitStackDropProc(CardRegion
&stackobj
, CardStack
&dragcards
)
231 TRACE("ENTER SuitStackDropProc()\n");
235 //only drop 1 card at a time
236 if(dragcards
.NumCards() != 1)
238 TRACE("EXIT SuitStackDropProc()\n");
242 bool b
= CanDrop(stackobj
, dragcards
[0]);
243 TRACE("EXIT SuitStackDropProc()\n");
247 if ((LastId
== PILE_ID
) || (LastId
>= ROW_ID
))
249 if (GetScoreMode() == SCORE_VEGAS
)
253 else if (GetScoreMode() == SCORE_STD
)
255 lScore
= lScore
+ 10;
266 // Single-click on one of the suit-stacks
268 void CARDLIBPROC
SuitStackClickProc(CardRegion
&stackobj
, int iNumClicked
)
270 TRACE("ENTER SuitStackClickProc()\n");
274 LastId
= stackobj
.Id();
276 TRACE("EXIT SuitStackClickProc()\n");
280 // Single-click on one of the row-stacks
281 // Turn the top-card over if they are all face-down
283 void CARDLIBPROC
RowStackClickProc(CardRegion
&stackobj
, int iNumClicked
)
285 TRACE("ENTER RowStackClickProc()\n");
288 stackobj
.GetFaceDirection(&numfacedown
);
290 //if all face-down, then make top card face-up
291 if(stackobj
.NumCards() == numfacedown
)
293 if(numfacedown
> 0) numfacedown
--;
294 stackobj
.SetFaceDirection(CS_FACE_DOWNUP
, numfacedown
);
297 if (GetScoreMode() == SCORE_STD
)
304 LastId
= stackobj
.Id();
308 TRACE("EXIT RowStackClickProc()\n");
312 // Find the suit-stack that can accept the specified card
314 CardRegion
*FindSuitStackFromCard(Card card
)
316 TRACE("ENTER FindSuitStackFromCard()\n");
318 for(int i
= 0; i
< 4; i
++)
320 if(CanDrop(*pSuitStack
[i
], card
))
322 TRACE("EXIT FindSuitStackFromCard()\n");
323 return pSuitStack
[i
];
327 TRACE("EXIT FindSuitStackFromCard()\n");
332 // What happens when we add a card to one of the suit stacks?
333 // Well, nothing (it is already added), but we need to
334 // check all four stacks (not just this one) to see if
335 // the game has finished.
337 void CARDLIBPROC
SuitStackAddProc(CardRegion
&stackobj
, const CardStack
&added
)
339 TRACE("ENTER SuitStackAddProc()\n");
340 bool fGameOver
= true;
344 for(int i
= 0; i
< 4; i
++)
346 if(pSuitStack
[i
]->NumCards() != 13)
356 KillTimer(hwndMain
, IDT_PLAYTIMER
);
359 if ((dwOptions
& OPTION_SHOW_TIME
) && (GetScoreMode() == SCORE_STD
))
361 lScore
= lScore
+ (700000 / dwTime
);
366 MessageBox(SolWnd
, MsgWin
, szAppName
, MB_OK
| MB_ICONINFORMATION
);
368 for(int i
= 0; i
< 4; i
++)
370 pSuitStack
[i
]->Flash(11, 100);
373 if( IDYES
== MessageBox(SolWnd
, MsgDeal
, szAppName
, MB_YESNO
| MB_ICONQUESTION
) )
379 SolWnd
.EmptyStacks();
381 fGameStarted
= false;
385 TRACE("EXIT SuitStackAddProc()\n");
389 // Double-click on one of the row stacks
390 // The aim is to find a suit-stack to move the
391 // double-clicked card to.
393 void CARDLIBPROC
RowStackDblClickProc(CardRegion
&stackobj
, int iNumClicked
)
395 TRACE("ENTER RowStackDblClickProc()\n");
399 //can only move 1 card at a time
402 TRACE("EXIT RowStackDblClickProc()\n");
406 //find a suit-stack to move the card to...
407 const CardStack
&cardstack
= stackobj
.GetCardStack();
408 CardRegion
*pDest
= FindSuitStackFromCard(cardstack
[0]);
415 //stackobj.MoveCards(pDest, 1, true);
416 //use the SimulateDrag funcion, because we get the
417 //AddProc callbacks called for us on the destination stacks...
418 stackobj
.SimulateDrag(pDest
, 1, true);
420 TRACE("EXIT RowStackDblClickProc()\n");
424 // Face-up pile single-click
426 void CARDLIBPROC
PileClickProc(CardRegion
&stackobj
, int iNumClicked
)
428 TRACE("ENTER SuitStackClickProc()\n");
432 LastId
= stackobj
.Id();
434 TRACE("EXIT SuitStackClickProc()\n");
438 // Face-up pile double-click
440 void CARDLIBPROC
PileDblClickProc(CardRegion
&stackobj
, int iNumClicked
)
442 TRACE("ENTER PileDblClickProc()\n");
446 RowStackDblClickProc(stackobj
, iNumClicked
);
447 TRACE("EXIT PileDblClickProc()\n");
451 // What happens when a card is removed from face-up pile?
453 void CARDLIBPROC
PileRemoveProc(CardRegion
&stackobj
, int iItems
)
455 TRACE("ENTER PileRemoveProc()\n");
459 //modify our "virtual" pile by removing the same card
460 //that was removed from the physical card stack
461 activepile
.Pop(iItems
);
463 //if there is just 1 card left, then modify the
464 //stack to contain ALL the face-up cards..the effect
465 //will be, the next time a card is dragged, all the
466 //previous card-triplets will be available underneath
467 if(stackobj
.NumCards() == 1)
469 stackobj
.SetOffsets(0,0);
470 stackobj
.SetCardStack(activepile
);
472 TRACE("EXIT PileRemoveProc()\n");
476 // Double-click on the deck
477 // Move 3 cards to the face-up pile
479 void CARDLIBPROC
DeckClickProc(CardRegion
&stackobj
, int iNumClicked
)
481 TRACE("ENTER DeckClickProc()\n");
485 CardStack cardstack
= stackobj
.GetCardStack();
486 CardStack pile
= pPile
->GetCardStack();
491 //reset the face-up pile to represent 3 cards
492 if(dwOptions
& OPTION_THREE_CARDS
)
493 pPile
->SetOffsets(CS_DEFXOFF
, 1);
495 if(cardstack
.NumCards() == 0)
497 if (GetScoreMode() == SCORE_VEGAS
)
499 if (dwWasteCount
< dwWasteTreshold
)
503 activepile
.Reverse();
504 cardstack
.Push(activepile
);
508 else if (GetScoreMode() == SCORE_STD
)
510 if ((dwWasteCount
>= dwWasteTreshold
) && (activepile
.NumCards() != 0))
512 if (dwOptions
& OPTION_THREE_CARDS
)
513 lScore
= lScore
>= 20 ? lScore
- 20 : 0;
515 lScore
= lScore
>= 100 ? lScore
- 100 : 0;
520 activepile
.Reverse();
521 cardstack
.Push(activepile
);
530 activepile
.Reverse();
531 cardstack
.Push(activepile
);
539 int numcards
= min((dwOptions
& OPTION_THREE_CARDS
) ? 3 : 1, cardstack
.NumCards());
541 //make a "visible" copy of these cards
543 temp
= cardstack
.Pop(numcards
);
546 if(dwOptions
& OPTION_THREE_CARDS
)
551 //remove the top 3 from deck
552 activepile
.Push(temp
);
557 pDeck
->SetCardStack(cardstack
);
558 pPile
->SetCardStack(pile
);
561 TRACE("EXIT DeckClickProc()\n");