Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

236 lines
7.7 KiB

  1. /***************************************************************************/
  2. /** Microsoft Windows **/
  3. /** Copyright(c) Microsoft Corp., 1991, 1992 **/
  4. /***************************************************************************/
  5. /****************************************************************************
  6. player.h
  7. Aug 92, JimH
  8. May 93, JimH chico port
  9. Header file for class player
  10. hierarchy: player
  11. / \
  12. computer human
  13. / \
  14. local_human remote_human
  15. note: player and human are abstract classes.
  16. pos == 0 implies local human
  17. id == 0 implies gamemeister
  18. Relative to any human player, positions (pos) are arranged like this:
  19. 2
  20. 1 3
  21. 0
  22. If the human is the gamemeister, these are also the id's.
  23. ****************************************************************************/
  24. #include "card.h"
  25. #include "debug.h"
  26. #include "ddeml.h"
  27. #ifndef PLAYER_INC
  28. #define PLAYER_INC
  29. const int HORZSPACING = 15;
  30. const int VERTSPACING = 15;
  31. const int IDGE = 3; // EDGE was defined as something else
  32. const int MAXCARDSWON = 14;
  33. typedef int SLOT;
  34. enum modetype { STARTING,
  35. SELECTING,
  36. DONE_SELECTING,
  37. WAITING,
  38. ACCEPTING,
  39. PLAYING,
  40. SCORING
  41. };
  42. const int MAXSLOT = 13;
  43. const int ALL = -1;
  44. struct handinfotype {
  45. int playerled; // id of player led
  46. int turn; // whose turn? (0 to 3)
  47. card *cardplayed[4]; // cards in play for each player
  48. BOOL bHeartsBroken; // hearts broken in this hand?
  49. BOOL bQSPlayed; // Queen of Spades played yet?
  50. BOOL bShootingRisk; // someone trying to shoot the moon?
  51. int nMoonShooter; // id of potential shooter
  52. BOOL bHumanShooter; // is nMoonShooter a human player?
  53. };
  54. /* timer callback */
  55. #if defined (MFC1)
  56. UINT FAR PASCAL EXPORT TimerBadMove(HWND hWnd, UINT nMsg, int nIDEvent, DWORD dwTime);
  57. #else
  58. void FAR PASCAL EXPORT TimerBadMove(HWND hWnd, UINT nMsg, UINT nIDEvent, DWORD dwTime);
  59. #endif
  60. class CMainWindow;
  61. class player {
  62. private:
  63. CString name;
  64. CFont font;
  65. protected:
  66. int id; // position relative to gamemeister
  67. int position; // position relative to you
  68. int score;
  69. card cd[MAXSLOT];
  70. POINT loc; // location of cd[0]
  71. int dx, dy; // offset for rest of cards
  72. POINT playloc; // played cards glided to here
  73. POINT homeloc; // won cards glided to here
  74. POINT dotloc; // location of cd[0] "selected" dot
  75. POINT nameloc; // location of name
  76. modetype mode;
  77. int status;
  78. int cardswon[MAXCARDSWON];
  79. int numcardswon;
  80. public:
  81. player(int n, int pos);
  82. virtual ~player() { } // required for ~local_human
  83. card *Card(int s) { return &(cd[s]); }
  84. void DisplayHeartsWon(CDC &dc);
  85. void DisplayName(CDC &dc);
  86. int EvaluateScore(BOOL &bMoonShot);
  87. BOOL GetCardLoc(SLOT s, POINT& loc);
  88. SLOT GetSlot(int id);
  89. CRect &GetCoverRect(CRect& rect);
  90. int GetID(SLOT slot) { return cd[slot].ID(); }
  91. CRect &GetMarkingRect(CRect& rect);
  92. modetype GetMode() { return mode; }
  93. CString GetName() { return name; }
  94. int GetScore() { return score; }
  95. void GlideToCentre(SLOT s, BOOL bFaceup);
  96. void MarkCardPlayed(SLOT s) { cd[s].Play(); }
  97. void ResetCardsWon(void);
  98. void ResetLoc(void);
  99. void ReturnSelectedCards(int c[]);
  100. void Select(SLOT slot, BOOL bSelect)
  101. { cd[slot].Select(bSelect); }
  102. void SetID(SLOT slot, int id) { cd[slot].SetID(id); }
  103. void SetMode(modetype m) { mode = m; }
  104. void SetName(CString& newname, CDC& dc);
  105. void SetScore(int s) { score = s; }
  106. void SetStatus(int s) { status = s; }
  107. void Sort(void);
  108. void WinCard(CDC &dc, card *c);
  109. virtual void Draw(CDC &dc, BOOL bCheating = FALSE, SLOT slot = ALL);
  110. virtual HCONV GetConv() { return NULL; }
  111. virtual BOOL IsHuman() { return FALSE; }
  112. virtual void MarkSelectedCards(CDC &dc);
  113. virtual void NotifyEndHand(handinfotype &h) = 0;
  114. virtual void NotifyNewRound(void) = 0;
  115. virtual void ReceiveSelectedCards(int c[]);
  116. virtual void SelectCardsToPass(void) = 0;
  117. virtual void SelectCardToPlay(handinfotype &h, BOOL bCheating) = 0;
  118. virtual void UpdateStatus(void) = 0;
  119. virtual void UpdateStatus(int stringid) = 0;
  120. virtual void UpdateStatus(const TCHAR *string) = 0;
  121. virtual void Quit() { }
  122. virtual BOOL HasQuit() { return FALSE; }
  123. };
  124. class human : public player {
  125. private:
  126. protected:
  127. human(int n, int pos);
  128. public:
  129. virtual BOOL IsHuman() { return TRUE; }
  130. #if defined(_DEBUG)
  131. void DebugMove(SLOT slot) { \
  132. TRACE1("<%d> human decides to ", id); PLAY(slot); TRACE0("\n"); }
  133. #endif
  134. };
  135. class remote_human : public human {
  136. private:
  137. HCONV m_hConv;
  138. BOOL bQuit;
  139. public:
  140. remote_human(int n, int pos, HCONV hConv);
  141. virtual HCONV GetConv() { return m_hConv; }
  142. virtual void NotifyEndHand(handinfotype &h) { }
  143. virtual void NotifyNewRound() { }
  144. virtual void SelectCardsToPass();
  145. virtual void SelectCardToPlay(handinfotype &h, BOOL bCheating);
  146. virtual void UpdateStatus() { }
  147. virtual void UpdateStatus(int stringid) { status = stringid; }
  148. virtual void UpdateStatus(const TCHAR *string) { }
  149. virtual void Quit() { bQuit = TRUE; }
  150. virtual BOOL HasQuit() { return bQuit; }
  151. };
  152. class local_human : public human {
  153. #if defined (MFC1)
  154. friend UINT FAR PASCAL EXPORT TimerBadMove(HWND, UINT, int, DWORD);
  155. #else
  156. friend void FAR PASCAL EXPORT TimerBadMove(HWND, UINT, UINT_PTR, DWORD);
  157. #endif
  158. protected:
  159. CBitmap m_bmStretchCard; // bitmap for card + pop length
  160. CStatusBarCtrl *m_pStatusWnd;
  161. int XYToCard(int x, int y);
  162. void StartTimer(card &c);
  163. static BOOL bTimerOn;
  164. static CString m_StatusText;
  165. public:
  166. local_human(int n);
  167. ~local_human();
  168. BOOL IsTimerOn() { return bTimerOn; }
  169. BOOL PlayCard(int x, int y, handinfotype &h, BOOL bCheating,
  170. BOOL bFlash = TRUE);
  171. void PopCard(CBrush &brush, int x, int y);
  172. void SetPlayerId(int n) { id = n; }
  173. void WaitMessage(const TCHAR *name);
  174. virtual void Draw(CDC &dc, BOOL bCheating = FALSE, SLOT slot = ALL);
  175. virtual void MarkSelectedCards(CDC &dc) { return; }
  176. virtual void NotifyEndHand(handinfotype &h) { return; }
  177. virtual void NotifyNewRound(void) { return; }
  178. virtual void ReceiveSelectedCards(int c[]);
  179. virtual void SelectCardsToPass(void);
  180. virtual void SelectCardToPlay(handinfotype &h, BOOL bCheating);
  181. virtual void UpdateStatus(void);
  182. virtual void UpdateStatus(int stringid);
  183. virtual void UpdateStatus(const TCHAR *string);
  184. };
  185. #endif // PLAYER_INC