]>
Commit | Line | Data |
---|---|---|
63cafd27 JS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: pile.h | |
3 | // Purpose: Forty Thieves patience game | |
4 | // Author: Chris Breeze | |
5 | // Modified by: | |
6 | // Created: 21/07/97 | |
7 | // RCS-ID: $Id$ | |
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 | //+-------------------------------------------------------------+ | |
14 | //| Description: | | |
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. | | |
20 | //| | | |
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. | | |
27 | //| | | |
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 | //+-------------------------------------------------------------+ | |
32 | #ifndef _PILE_H_ | |
33 | #define _PILE_H_ | |
34 | #include "card.h" | |
35 | ||
36 | const int NumCards = 2 * PackSize; | |
37 | ||
38 | ||
39 | //----------------------------------------------------------------// | |
40 | // A class defining a pile of cards with a position on the screen // | |
41 | //----------------------------------------------------------------// | |
42 | class Pile { | |
43 | public: | |
44 | Pile(int x, int y, int dx = 0, int dy = 0); | |
45 | virtual ~Pile(); | |
46 | ||
47 | // General functions | |
48 | virtual void ResetPile() { m_topCard = -1; } | |
49 | virtual void Redraw(wxDC& pDC); | |
50 | ||
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 | |
62 | ||
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); | |
67 | ||
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 | |
fc799548 | 72 | void SetPos(int x,int y) {m_x = x;m_y = y;}; |
63cafd27 JS |
73 | |
74 | protected: | |
75 | int m_x, m_y; // Position of the pile on the screen | |
76 | int m_dx, m_dy; // Offset when drawing the pile | |
77 | Card* m_cards[NumCards]; // Array of cards in this pile | |
78 | int m_topCard; // Array index of the top card | |
79 | }; | |
80 | ||
81 | #endif // _PILE_H_ |