1 /////////////////////////////////////////////////////////////////////////////
2 // Name:        pile.h
3 // Purpose:     Forty Thieves patience game
4 // Author:      Chris Breeze
5 // Modified by:
6 // Created:     21/07/97
7 // Copyright:   (c) 1993-1998 Chris Breeze
8 // Licence:     wxWindows licence
9 //---------------------------------------------------------------------------
10 // Last modified: 22nd July 1998 - ported to wxWidgets 2.0
11 /////////////////////////////////////////////////////////////////////////////
12 //+-------------------------------------------------------------+
13 //| Description:                                                |
14 //| The base class for holding piles of playing cards.          |
15 //| This is the basic building block for card games. A pile     |
16 //| has a position on the screen and an offset for each         |
17 //| card placed on it e.g. a pack has no offset, but the        |
18 //| discard pile may be fanned out across the screen.           |
19 //|                                                             |
20 //| The pile knows how to draw itself, though this may be       |
21 //| overridden if the default layout needs to be changed.       |
22 //| One or more cards can be removed from the top of a pile,    |
23 //| and single cards can be added to the top of a pile.         |
24 //| Functions are provided which redraw the screen when         |
25 //| cards are added or removed.                                 |
26 //|                                                             |
27 //| Cards know which way up they are and how to draw            |
28 //| themselves. Piles are lists of cards. Piles know which      |
29 //| cards they contain and where they are to be drawn.          |
30 //+-------------------------------------------------------------+
31 #ifndef _PILE_H_
32 #define _PILE_H_
33 #include "card.h"
34 
35 const int NumCards = 2 * PackSize;
36 
37 
38 //----------------------------------------------------------------//
39 // A class defining a pile of cards with a position on the screen //
40 //----------------------------------------------------------------//
41 class Pile {
42 public:
43     Pile(int x, int y, int dx = 0, int dy = 0);
~Pile()44     virtual ~Pile(){};
45 
46     // General functions
ResetPile()47     virtual void ResetPile() { m_topCard = -1; }
48     virtual void Redraw(wxDC& pDC);
49 
50     // Card query functions
51     virtual Card* GetCard(int x, int y); // Get pointer to card at x, y
52     Card* GetTopCard();                     // Get pointer to top card
53     virtual void GetCardPos(Card* card, int& x, int& y);
54     // Get position of a card
55     virtual void GetTopCardPos(int& x, int& y);
56     // Get position of the top card
GetNumCards()57     int GetNumCards() { return m_topCard + 1; } // Number of cards in pile
58     bool Overlap(int x, int y); // does card at x,y overlap the pile?
59     int CalcDistance(int x, int y); // calculates the square of the distance
60                                     // of a card at (x,y) from the top of the pile
61 
62     // Functions removing one or more cards from the top of a pile
63     virtual bool CanCardLeave(Card* card);
64     Card* RemoveTopCard();
65     virtual Card* RemoveTopCard(wxDC& pDC, int xOffset = 0, int yOffset = 0);
66 
67     // Functions to add a card to the top of a pile
AcceptCard(Card *)68     virtual bool AcceptCard(Card*) { return false; }
69     virtual void AddCard(Card* card); // Add card to top of pile
70     virtual void AddCard(wxDC& pDC, Card* card); // Add card + redraw it
SetPos(int x,int y)71         void SetPos(int x,int y) {m_x = x;m_y = y;};
72 
73 protected:
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
78 };
79 
80 #endif // _PILE_H_
81