19219b8f9f4045855231d1defa732f6a5d39c344
6 #define TRACE(s) printf("%s(%i): %s",__FILE__,__LINE__,s)
9 extern TCHAR MsgWin
[128];
10 extern TCHAR MsgDeal
[128];
15 bool fGameStarted
= false;
16 bool bAutoroute
= false;
20 TRACE("ENTER NewGame()\n");
23 if (GetScoreMode() == SCORE_VEGAS
)
25 if ((dwOptions
& OPTION_KEEP_SCORE
) && (dwPrevMode
== SCORE_VEGAS
))
30 if (dwOptions
& OPTION_THREE_CARDS
)
38 if (dwOptions
& OPTION_THREE_CARDS
)
52 //create a new card-stack
59 //deal to each row stack..
60 for(i
= 0; i
< NUM_ROW_STACKS
; i
++)
65 pRowStack
[i
]->SetFaceDirection(CS_FACE_DOWNUP
, i
);
67 for(j
= 0; j
<= i
; j
++)
69 temp
.Push(deck
.Pop());
72 pRowStack
[i
]->SetCardStack(temp
);
75 //put the other cards onto the deck
76 pDeck
->SetCardStack(deck
);
79 // For the 1-card-mode, all cards need to be completely overlapped
80 if(!(dwOptions
& OPTION_THREE_CARDS
))
81 pPile
->SetOffsets(0, 0);
87 dwPrevMode
= GetScoreMode();
92 TRACE("EXIT NewGame()\n");
97 // Now follow the stack callback functions. This is where we
98 // provide the game functionality and rules
102 // Can only drag face-up cards
104 bool CARDLIBPROC
RowStackDragProc(CardRegion
&stackobj
, int iNumDragCards
)
106 TRACE("ENTER RowStackDragProc()\n");
112 stackobj
.GetFaceDirection(&numfacedown
);
114 numcards
= stackobj
.NumCards();
116 TRACE("EXIT RowStackDragProc()\n");
117 if(iNumDragCards
<= numcards
-numfacedown
)
125 // Row a row-stack, we can only drop cards
126 // that are lower / different colour
128 bool CARDLIBPROC
RowStackDropProc(CardRegion
&stackobj
, CardStack
&dragcards
)
130 TRACE("ENTER RowStackDropProc()\n");
131 Card dragcard
= dragcards
[dragcards
.NumCards() - 1];
135 //if we are empty, can only drop a stack with a King at bottom
136 if(stackobj
.NumCards() == 0)
138 if(dragcard
.LoVal() != 13)
140 TRACE("EXIT RowStackDropProc(false)\n");
146 const CardStack
&mystack
= stackobj
.GetCardStack();
148 //can only drop if card is 1 less
149 if(mystack
[0].LoVal() != dragcard
.LoVal() + 1)
151 TRACE("EXIT RowStackDropProc(false)\n");
155 //can only drop if card is different colour
156 if( (mystack
[0].IsBlack() && !dragcard
.IsRed()) ||
157 (!mystack
[0].IsBlack() && dragcard
.IsRed()) )
159 TRACE("EXIT RowStackDropProc(false)\n");
166 SetUndo(LastId
, stackobj
.Id(), dragcards
.NumCards(), lScore
, VisiblePileCards
);
168 if (LastId
== PILE_ID
)
170 if (GetScoreMode() == SCORE_STD
)
175 else if ((LastId
>= SUIT_ID
) && (LastId
<= SUIT_ID
+ 3))
177 if (GetScoreMode() == SCORE_STD
)
179 lScore
= lScore
>= 15 ? lScore
- 15 : 0;
181 else if (GetScoreMode() == SCORE_VEGAS
)
183 lScore
= lScore
>= -47 ? lScore
- 5 : -52;
189 TRACE("EXIT RowStackDropProc(true)\n");
194 // Can only drop a card onto a suit-stack if the
195 // card is 1 higher, and is the same suit
197 bool CanDrop(CardRegion
&stackobj
, Card card
)
199 TRACE("ENTER CanDrop()\n");
202 const CardStack
&cardstack
= stackobj
.GetCardStack();
206 if(cardstack
.NumCards() > 0)
208 if(card
.Suit() != cardstack
[0].Suit())
210 TRACE("EXIT CanDrop()\n");
214 topval
= cardstack
[0].LoVal();
222 if(card
.LoVal() != (topval
+ 1))
224 TRACE("EXIT CanDrop()\n");
228 TRACE("EXIT CanDrop()\n");
233 // Can only drop a card onto suit stack if it is same suit, and 1 higher
235 bool CARDLIBPROC
SuitStackDropProc(CardRegion
&stackobj
, CardStack
&dragcards
)
237 TRACE("ENTER SuitStackDropProc()\n");
241 //only drop 1 card at a time
242 if (!bAutoroute
&& dragcards
.NumCards() != 1)
244 TRACE("EXIT SuitStackDropProc()\n");
248 bool b
= CanDrop(stackobj
, dragcards
[0]);
249 TRACE("EXIT SuitStackDropProc()\n");
253 SetUndo(LastId
, stackobj
.Id(), 1, lScore
, VisiblePileCards
);
255 if ((LastId
== PILE_ID
) || (LastId
>= ROW_ID
))
257 if (GetScoreMode() == SCORE_VEGAS
)
261 else if (GetScoreMode() == SCORE_STD
)
263 lScore
= lScore
+ 10;
274 // Single-click on one of the suit-stacks
276 void CARDLIBPROC
SuitStackClickProc(CardRegion
&stackobj
, int iNumClicked
)
278 TRACE("ENTER SuitStackClickProc()\n");
282 LastId
= stackobj
.Id();
284 TRACE("EXIT SuitStackClickProc()\n");
288 // Single-click on one of the row-stacks
289 // Turn the top-card over if they are all face-down
291 void CARDLIBPROC
RowStackClickProc(CardRegion
&stackobj
, int iNumClicked
)
293 TRACE("ENTER RowStackClickProc()\n");
296 stackobj
.GetFaceDirection(&numfacedown
);
298 //if all face-down, then make top card face-up
299 if(stackobj
.NumCards() == numfacedown
)
301 if(numfacedown
> 0) numfacedown
--;
302 stackobj
.SetFaceDirection(CS_FACE_DOWNUP
, numfacedown
);
305 if (GetScoreMode() == SCORE_STD
)
313 LastId
= stackobj
.Id();
317 TRACE("EXIT RowStackClickProc()\n");
321 // Find the suit-stack that can accept the specified card
323 CardRegion
*FindSuitStackFromCard(Card card
)
325 TRACE("ENTER FindSuitStackFromCard()\n");
327 for(int i
= 0; i
< 4; i
++)
329 if(CanDrop(*pSuitStack
[i
], card
))
331 TRACE("EXIT FindSuitStackFromCard()\n");
332 return pSuitStack
[i
];
336 TRACE("EXIT FindSuitStackFromCard()\n");
341 // What happens when we add a card to one of the suit stacks?
342 // Well, nothing (it is already added), but we need to
343 // check all four stacks (not just this one) to see if
344 // the game has finished.
346 void CARDLIBPROC
SuitStackAddProc(CardRegion
&stackobj
, const CardStack
&added
)
348 TRACE("ENTER SuitStackAddProc()\n");
349 bool fGameOver
= true;
353 for(int i
= 0; i
< 4; i
++)
355 if(pSuitStack
[i
]->NumCards() != 13)
365 KillTimer(hwndMain
, IDT_PLAYTIMER
);
368 if ((dwOptions
& OPTION_SHOW_TIME
) && (GetScoreMode() == SCORE_STD
))
370 lScore
= lScore
+ (700000 / dwTime
);
376 MessageBox(SolWnd
, MsgWin
, szAppName
, MB_OK
| MB_ICONINFORMATION
);
378 for(int i
= 0; i
< 4; i
++)
380 pSuitStack
[i
]->Flash(11, 100);
383 if( IDYES
== MessageBox(SolWnd
, MsgDeal
, szAppName
, MB_YESNO
| MB_ICONQUESTION
) )
389 SolWnd
.EmptyStacks();
391 fGameStarted
= false;
395 TRACE("EXIT SuitStackAddProc()\n");
399 // Double-click on one of the row stacks
400 // The aim is to find a suit-stack to move the
401 // double-clicked card to.
403 void CARDLIBPROC
RowStackDblClickProc(CardRegion
&stackobj
, int iNumClicked
)
405 TRACE("ENTER RowStackDblClickProc()\n");
409 //can only move 1 card at a time
412 TRACE("EXIT RowStackDblClickProc()\n");
416 //find a suit-stack to move the card to...
417 const CardStack
&cardstack
= stackobj
.GetCardStack();
418 CardRegion
*pDest
= FindSuitStackFromCard(cardstack
[0]);
425 //stackobj.MoveCards(pDest, 1, true);
426 //use the SimulateDrag function, because we get the
427 //AddProc callbacks called for us on the destination stacks...
429 stackobj
.SimulateDrag(pDest
, 1, true);
432 TRACE("EXIT RowStackDblClickProc()\n");
436 // Face-up pile single-click
438 void CARDLIBPROC
PileClickProc(CardRegion
&stackobj
, int iNumClicked
)
440 TRACE("ENTER SuitStackClickProc()\n");
444 LastId
= stackobj
.Id();
446 TRACE("EXIT SuitStackClickProc()\n");
450 // Face-up pile double-click
452 void CARDLIBPROC
PileDblClickProc(CardRegion
&stackobj
, int iNumClicked
)
454 TRACE("ENTER PileDblClickProc()\n");
458 RowStackDblClickProc(stackobj
, iNumClicked
);
459 TRACE("EXIT PileDblClickProc()\n");
463 // Fix for the 3-card play when only 1 card left on the pile.
465 void FixIfOneCardLeft(void)
467 // If there is just 1 card left, then modify the
468 // stack to contain ALL the face-up cards. The effect
469 // will be, the next time a card is dragged, all the
470 // previous card-triplets will be available underneath.
471 if ((dwOptions
& OPTION_THREE_CARDS
) && pPile
->NumCards() == 1)
473 pPile
->SetOffsets(0, 0);
474 pPile
->SetCardStack(activepile
);
479 // What happens when a card is removed from face-up pile?
481 void CARDLIBPROC
PileRemoveProc(CardRegion
&stackobj
, int iItems
)
483 TRACE("ENTER PileRemoveProc()\n");
487 //modify our "virtual" pile by removing the same card
488 //that was removed from the physical card stack
489 activepile
.Pop(iItems
);
490 if ((dwOptions
& OPTION_THREE_CARDS
) && (VisiblePileCards
> 1))
497 TRACE("EXIT PileRemoveProc()\n");
501 // Double-click on the deck
502 // Move 3 cards to the face-up pile
504 void CARDLIBPROC
DeckClickProc(CardRegion
&stackobj
, int iNumClicked
)
506 TRACE("ENTER DeckClickProc()\n");
510 CardStack cardstack
= stackobj
.GetCardStack();
511 CardStack pile
= pPile
->GetCardStack();
516 //reset the face-up pile to represent 3 cards
517 if(dwOptions
& OPTION_THREE_CARDS
)
518 pPile
->SetOffsets(CS_DEFXOFF
, 1);
520 if(cardstack
.NumCards() == 0)
522 if (GetScoreMode() == SCORE_VEGAS
)
524 if (dwWasteCount
< dwWasteTreshold
)
528 activepile
.Reverse();
529 cardstack
.Push(activepile
);
531 SetUndo(PILE_ID
, DECK_ID
, cardstack
.NumCards(), lScore
, VisiblePileCards
);
532 VisiblePileCards
= 0;
535 else if (GetScoreMode() == SCORE_STD
)
537 SetUndo(PILE_ID
, DECK_ID
, activepile
.NumCards(), lScore
, VisiblePileCards
);
538 if ((dwWasteCount
>= dwWasteTreshold
) && (activepile
.NumCards() != 0))
540 if (dwOptions
& OPTION_THREE_CARDS
)
541 lScore
= lScore
>= 20 ? lScore
- 20 : 0;
543 lScore
= lScore
>= 100 ? lScore
- 100 : 0;
548 activepile
.Reverse();
549 cardstack
.Push(activepile
);
551 VisiblePileCards
= 0;
559 activepile
.Reverse();
560 cardstack
.Push(activepile
);
562 SetUndo(PILE_ID
, DECK_ID
, cardstack
.NumCards(), lScore
, VisiblePileCards
);
563 VisiblePileCards
= 0;
570 int numcards
= min((dwOptions
& OPTION_THREE_CARDS
) ? 3 : 1, cardstack
.NumCards());
572 SetUndo(DECK_ID
, PILE_ID
, numcards
, lScore
, VisiblePileCards
);
574 //make a "visible" copy of these cards
576 temp
= cardstack
.Pop(numcards
);
579 if(dwOptions
& OPTION_THREE_CARDS
)
584 //remove the top 3 from deck
585 activepile
.Push(temp
);
587 VisiblePileCards
= numcards
;
592 pDeck
->SetCardStack(cardstack
);
593 pPile
->SetCardStack(pile
);
598 TRACE("EXIT DeckClickProc()\n");