]>
git.saurik.com Git - wxWidgets.git/blob - demos/forty/pile.h
49eb8c9b54338f3cf6f3fbf6f0c5328d6e075c84
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Forty Thieves patience game
4 // Author: Chris Breeze
8 // Copyright: (c) 1993-1998 Chris Breeze
9 // Licence: wxWindows licence
10 //---------------------------------------------------------------------------
11 // Last modified: 22nd July 1998 - ported to wxWindows 2.0
12 /////////////////////////////////////////////////////////////////////////////
13 //+-------------------------------------------------------------+
15 //| The base class for holding piles of playing cards. |
16 //| This is the basic building block for card games. A pile |
17 //| has a position on the screen and an offset for each |
18 //| card placed on it e.g. a pack has no offset, but the |
19 //| discard pile may be fanned out across the screen. |
21 //| The pile knows how to draw itself, though this may be |
22 //| overridden if the default layout needs to be changed. |
23 //| One or more cards can be removed from the top of a pile, |
24 //| and single cards can be added to the top of a pile. |
25 //| Functions are provided which redraw the screen when |
26 //| cards are added or removed. |
28 //| Cards know which way up they are and how to draw |
29 //| themselves. Piles are lists of cards. Piles know which |
30 //| cards they contain and where they are to be drawn. |
31 //+-------------------------------------------------------------+
36 const int NumCards
= 2 * PackSize
;
39 //----------------------------------------------------------------//
40 // A class defining a pile of cards with a position on the screen //
41 //----------------------------------------------------------------//
44 Pile(int x
, int y
, int dx
= 0, int dy
= 0);
48 virtual void ResetPile() { m_topCard
= -1; }
49 virtual void Redraw(wxDC
& pDC
);
51 // Card query functions
52 virtual Card
* GetCard(int x
, int y
); // Get pointer to card at x, y
53 Card
* GetTopCard(); // Get pointer to top card
54 virtual void GetCardPos(Card
* card
, int& x
, int& y
);
55 // Get position of a card
56 virtual void GetTopCardPos(int& x
, int& y
);
57 // Get position of the top card
58 int GetNumCards() { return m_topCard
+ 1; } // Number of cards in pile
59 bool Overlap(int x
, int y
); // does card at x,y overlap the pile?
60 int CalcDistance(int x
, int y
); // calculates the square of the distance
61 // of a card at (x,y) from the top of the pile
63 // Functions removing one or more cards from the top of a pile
64 virtual bool CanCardLeave(Card
* card
);
65 Card
* RemoveTopCard();
66 virtual Card
* RemoveTopCard(wxDC
& pDC
, int xOffset
= 0, int yOffset
= 0);
68 // Functions to add a card to the top of a pile
69 virtual bool AcceptCard(Card
*) { return FALSE
; }
70 virtual void AddCard(Card
* card
); // Add card to top of pile
71 virtual void AddCard(wxDC
& pDC
, Card
* card
); // Add card + redraw it
74 int m_x
, m_y
; // Position of the pile on the screen
75 int m_dx
, m_dy
; // Offset when drawing the pile
76 Card
* m_cards
[NumCards
]; // Array of cards in this pile
77 int m_topCard
; // Array index of the top card