game.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: game.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. #ifndef _GAME_H_
  13. #define _GAME_H_
  14. #include "card.h"
  15. #include "pile.h"
  16. const int MaxMoves = 800;
  17. //---------------------------------------//
  18. // A class which holds the pack of cards //
  19. //---------------------------------------//
  20. class Pack : public Pile {
  21. public:
  22. Pack(int x, int y);
  23. virtual ~Pack();
  24. void Redraw(wxDC& dc);
  25. void ResetPile() { m_topCard = NumCards - 1; }
  26. void Shuffle();
  27. void AddCard(Card* card); // Add card
  28. void AddCard(wxDC& dc, Card* card) { AddCard(card); Redraw(dc); }
  29. };
  30. //----------------------------------------------------------//
  31. // A class which holds a base i.e. the initial 10 x 4 cards //
  32. //----------------------------------------------------------//
  33. class Base : public Pile {
  34. public:
  35. Base(int x, int y);
  36. virtual ~Base(){}
  37. bool AcceptCard(Card* card);
  38. };
  39. //----------------------------------------------------//
  40. // A class which holds a foundation i.e. Ace, 2, 3... //
  41. //----------------------------------------------------//
  42. class Foundation : public Pile {
  43. public:
  44. Foundation(int x, int y);
  45. virtual ~Foundation(){}
  46. bool AcceptCard(Card* card);
  47. };
  48. //--------------------------------------//
  49. // A class which holds the discard pile //
  50. //--------------------------------------//
  51. class Discard : public Pile {
  52. public:
  53. Discard(int x, int y);
  54. virtual ~Discard(){}
  55. void Redraw(wxDC& dc);
  56. void GetTopCardPos(int& x, int& y);
  57. Card* RemoveTopCard(wxDC& dc, int m_xOffset, int m_yOffset);
  58. };
  59. class Game {
  60. public:
  61. Game(int wins, int games, int score);
  62. virtual ~Game();
  63. void Layout();
  64. void NewPlayer(int wins, int games, int score);
  65. void Deal(); // Shuffle and deal a new game
  66. bool CanYouGo(int x, int y); // can card under (x,y) go somewhere?
  67. bool HaveYouWon(); // have you won the game?
  68. void Undo(wxDC& dc); // Undo the last go
  69. void Redo(wxDC& dc); // Redo the last go
  70. void Redraw(wxDC& dc);
  71. void DisplayScore(wxDC& dc);
  72. bool LButtonDown(wxDC& dc, int mx, int my);
  73. void LButtonUp(wxDC& dc, int mx, int my);
  74. void LButtonDblClk(wxDC& dc, int mx, int my);
  75. void MouseMove(wxDC& dc, int mx, int my);
  76. int GetNumWins() const { return m_numWins; }
  77. int GetNumGames() const { return m_numGames; }
  78. int GetScore() const { return m_currentScore + m_totalScore; }
  79. bool InPlay() const { return m_inPlay; }
  80. private:
  81. bool DropCard(int x, int y, Pile* pile, Card* card);
  82. // can the card at (x, y) be dropped on the pile?
  83. Pile* WhichPile(int x, int y); // which pile is (x, y) over?
  84. void DoMove(wxDC& dc, Pile* src, Pile* dest);
  85. bool m_inPlay; // flag indicating that the game has started
  86. // undo buffer
  87. struct {
  88. Pile* src;
  89. Pile* dest;
  90. } m_moves[MaxMoves];
  91. int m_moveIndex; // current position in undo/redo buffer
  92. int m_redoIndex; // max move index available for redo
  93. // the various piles of cards
  94. Pack* m_pack;
  95. Discard* m_discard;
  96. Base* m_bases[10];
  97. Foundation* m_foundations[8];
  98. // variables to do with dragging cards
  99. Pile* m_srcPile;
  100. Card* m_liftedCard;
  101. int m_xPos, m_yPos; // current coords of card being dragged
  102. int m_xOffset, m_yOffset; // card/mouse offset when dragging a card
  103. wxBitmap* m_bmap;
  104. wxBitmap* m_bmapCard;
  105. // variables to do with scoring
  106. int m_numGames;
  107. int m_numWins;
  108. int m_totalScore;
  109. int m_currentScore;
  110. };
  111. #endif // _GAME_H_