pile.h 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. const int NumCards = 2 * PackSize;
  35. //----------------------------------------------------------------//
  36. // A class defining a pile of cards with a position on the screen //
  37. //----------------------------------------------------------------//
  38. class Pile {
  39. public:
  40. Pile(int x, int y, int dx = 0, int dy = 0);
  41. virtual ~Pile(){};
  42. // General functions
  43. virtual void ResetPile() { m_topCard = -1; }
  44. virtual void Redraw(wxDC& pDC);
  45. // Card query functions
  46. virtual Card* GetCard(int x, int y); // Get pointer to card at x, y
  47. Card* GetTopCard(); // Get pointer to top card
  48. virtual void GetCardPos(Card* card, int& x, int& y);
  49. // Get position of a card
  50. virtual void GetTopCardPos(int& x, int& y);
  51. // Get position of the top card
  52. int GetNumCards() { return m_topCard + 1; } // Number of cards in pile
  53. bool Overlap(int x, int y); // does card at x,y overlap the pile?
  54. int CalcDistance(int x, int y); // calculates the square of the distance
  55. // of a card at (x,y) from the top of the pile
  56. // Functions removing one or more cards from the top of a pile
  57. virtual bool CanCardLeave(Card* card);
  58. Card* RemoveTopCard();
  59. virtual Card* RemoveTopCard(wxDC& pDC, int xOffset = 0, int yOffset = 0);
  60. // Functions to add a card to the top of a pile
  61. virtual bool AcceptCard(Card*) { return false; }
  62. virtual void AddCard(Card* card); // Add card to top of pile
  63. virtual void AddCard(wxDC& pDC, Card* card); // Add card + redraw it
  64. void SetPos(int x,int y) {m_x = x;m_y = y;};
  65. protected:
  66. int m_x, m_y; // Position of the pile on the screen
  67. int m_dx, m_dy; // Offset when drawing the pile
  68. Card* m_cards[NumCards]; // Array of cards in this pile
  69. int m_topCard; // Array index of the top card
  70. };
  71. #endif // _PILE_H_