home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / scase.zip / SCASE.Z / CXVTTTWN.CC < prev    next >
C/C++ Source or Header  |  1994-10-17  |  7KB  |  208 lines

  1. /******************************************************************************
  2. *                         ** Company Confidential **
  3. *                  ** Copyright 1994, All rights Reserved **
  4. * %Z%%M% version %I% date:%G%
  5. ******************************************************************************/
  6.  
  7. // -MQBeg- [Module_Includes] [cxvtttwn_cc] <00000028.00000000> Retained!
  8. #include "PwrDef.h"
  9. #include "AppDef.h"
  10. #include CTypeInfo_i
  11. #include CDocument_i
  12. #include CWindow_i
  13.  
  14. #include "ttteng.h"
  15. #include "tttdisp.h"
  16. #include "tttcont.h"
  17.  
  18. #include XVTTTT_i
  19. #include CXVTTTTDoc_i
  20. #include CXVTTTTWin_i
  21. // -MQEnd- [Module_Includes] [cxvtttwn_cc] <00000028.00000000> 
  22.  
  23. // -MQBeg- [Module_Declarations_1] [cxvtttwn_cc] <00000028.00000000> Retained!
  24. // -MQEnd- [Module_Declarations_1] [cxvtttwn_cc] <00000028.00000000> 
  25.  
  26. // -MQBeg- [Class_Body] [CXVTTTTWin] <00000000.00000013> 
  27. /******************************************************************************
  28.                                   CXVTTTTWin
  29. ******************************************************************************/
  30.  
  31. CXVTTTTWin::CXVTTTTWin(TTT_Engine *Engine, CDocument *theDocument, const CRect& theRegion, const CStringRW& theTitle , long theWindowAttributes, WIN_TYPE theWindowType, int theMenuBarId)
  32. // -MQBeg- [Op_Init] [CXVTTTTWin::CXVTTTTWin] <00000030.00000029> Retained!
  33. : TTT_Display(Engine), TTT_Controller(Engine, this),
  34.   CWindow(theDocument, theRegion, theTitle,
  35.   theWindowAttributes, theWindowType, theMenuBarId)
  36. // -MQEnd- [Op_Init] [CXVTTTTWin::CXVTTTTWin] <00000030.00000029> 
  37. {
  38. // -MQBeg- [Op_Body] [CXVTTTTWin::CXVTTTTWin] <00000030.00000029> Retained!
  39. // -MQEnd- [Op_Body] [CXVTTTTWin::CXVTTTTWin] <00000030.00000029> 
  40. }
  41.  
  42. CXVTTTTWin::~CXVTTTTWin()
  43. {
  44. // -MQBeg- [Op_Body] [CXVTTTTWin::~CXVTTTTWin] <00000030.0000002A> Retained!
  45.   theDisplay = NULL;  // So that the base class does not delete this!!
  46. // -MQEnd- [Op_Body] [CXVTTTTWin::~CXVTTTTWin] <00000030.0000002A> 
  47. }
  48.  
  49. void
  50. CXVTTTTWin::DisplayWelcomeMsg()
  51. {
  52. // -MQBeg- [Op_Body] [CXVTTTTWin::DisplayWelcomeMsg] <00000030.0000002B> Retained!
  53.   xvt_dm_post_note("Welcome to Tic Tac Toe");
  54. // -MQEnd- [Op_Body] [CXVTTTTWin::DisplayWelcomeMsg] <00000030.0000002B> 
  55. }
  56.  
  57. void
  58. CXVTTTTWin::DisplayIllegalMove()
  59. {
  60. // -MQBeg- [Op_Body] [CXVTTTTWin::DisplayIllegalMove] <00000030.0000002C> Retained!
  61.   xvt_scr_beep();
  62. // -MQEnd- [Op_Body] [CXVTTTTWin::DisplayIllegalMove] <00000030.0000002C> 
  63. }
  64.  
  65. void
  66. CXVTTTTWin::DisplayYouWin()
  67. {
  68. // -MQBeg- [Op_Body] [CXVTTTTWin::DisplayYouWin] <00000030.0000002D> Retained!
  69.   xvt_dm_post_note("You win!");
  70. // -MQEnd- [Op_Body] [CXVTTTTWin::DisplayYouWin] <00000030.0000002D> 
  71. }
  72.  
  73. void
  74. CXVTTTTWin::DisplayYouLose()
  75. {
  76. // -MQBeg- [Op_Body] [CXVTTTTWin::DisplayYouLose] <00000030.0000002E> Retained!
  77.   xvt_dm_post_note("You lose!");
  78. // -MQEnd- [Op_Body] [CXVTTTTWin::DisplayYouLose] <00000030.0000002E> 
  79. }
  80.  
  81. void
  82. CXVTTTTWin::DisplayDraw()
  83. {
  84. // -MQBeg- [Op_Body] [CXVTTTTWin::DisplayDraw] <00000030.0000002F> Retained!
  85.   xvt_dm_post_note("It's a draw!");
  86. // -MQEnd- [Op_Body] [CXVTTTTWin::DisplayDraw] <00000030.0000002F> 
  87. }
  88.  
  89. void
  90. CXVTTTTWin::DrawGrid()
  91. {
  92. // -MQBeg- [Op_Body] [CXVTTTTWin::DrawGrid] <00000030.00000030> Retained!
  93.   PNT p;
  94.   WINDOW w = GetXVTWindow();
  95.   xvt_dwin_set_std_cpen(w, TL_PEN_BLACK);
  96.   
  97.   p.h=BOARDXOFFSET+SW_SIZE;     p.v=BOARDYOFFSET;             xvt_dwin_draw_set_pos(w, p);
  98.   p.h=BOARDXOFFSET+SW_SIZE;     p.v=BOARDYOFFSET+(SW_SIZE*3); xvt_dwin_draw_line(w, p);
  99.   
  100.   p.h=BOARDXOFFSET+(SW_SIZE*2); p.v=BOARDYOFFSET;             xvt_dwin_draw_set_pos(w, p);
  101.   p.h=BOARDXOFFSET+(SW_SIZE*2); p.v=BOARDYOFFSET+(SW_SIZE*3); xvt_dwin_draw_line(w, p);
  102.   
  103.   p.h=BOARDXOFFSET;             p.v=BOARDYOFFSET+SW_SIZE;     xvt_dwin_draw_set_pos(w, p);
  104.   p.h=BOARDXOFFSET+(SW_SIZE*3); p.v=BOARDYOFFSET+SW_SIZE;     xvt_dwin_draw_line(w, p);
  105.   
  106.   p.h=BOARDXOFFSET;             p.v=BOARDYOFFSET+(SW_SIZE*2); xvt_dwin_draw_set_pos(w, p);
  107.   p.h=BOARDXOFFSET+(SW_SIZE*3); p.v=BOARDYOFFSET+(SW_SIZE*2); xvt_dwin_draw_line(w, p);
  108. // -MQEnd- [Op_Body] [CXVTTTTWin::DrawGrid] <00000030.00000030> 
  109. }
  110.  
  111. void
  112. CXVTTTTWin::Draw(const CRect& /*theClippingRegion*/ )
  113. {
  114. // -MQBeg- [Op_Body] [CXVTTTTWin::Draw] <00000030.00000031> Retained!
  115.   this->HandleEvent(TTT_Controller::UPDATE);
  116. // -MQEnd- [Op_Body] [CXVTTTTWin::Draw] <00000030.00000031> 
  117. }
  118.  
  119. void
  120. CXVTTTTWin::DoMouseDown(CPoint theLocation, short /*theButton*/, BOOLEAN /*isShiftKey*/, BOOLEAN /*isControlKey*/)
  121. {
  122. // -MQBeg- [Op_Body] [CXVTTTTWin::DoMouseDown] <00000030.00000032> Retained!
  123.   for (int Row=0; Row<3; Row++)
  124.     for (int Col=0; Col<3; Col++)
  125.     {
  126.       CRect r( this->GetRect(Row, Col) );
  127.       if ( r.IsPointInRect(theLocation) )
  128.       {
  129.         this->HandleEvent(TTT_Controller::MOVE, Row*3+Col);
  130.         return;
  131.       }  
  132.     }
  133. // -MQEnd- [Op_Body] [CXVTTTTWin::DoMouseDown] <00000030.00000032> 
  134. }
  135.  
  136. void
  137. CXVTTTTWin::DoMenuCommand(MENU_TAG theMenuItem, BOOLEAN isShiftKey, BOOLEAN isControlKey)
  138. {
  139. // -MQBeg- [Op_Body] [CXVTTTTWin::DoMenuCommand] <00000030.00000033> Retained!
  140.   switch (theMenuItem)
  141.   {
  142.   case MENU_GAME_RESET:
  143.     this->HandleEvent(TTT_Controller::RESET);
  144.     break;
  145.   default:
  146.     CWindow::DoMenuCommand(theMenuItem, isShiftKey, isControlKey);
  147.     break;
  148.   }
  149. // -MQEnd- [Op_Body] [CXVTTTTWin::DoMenuCommand] <00000030.00000033> 
  150. }
  151.  
  152. void
  153. CXVTTTTWin::ClearDisplay()
  154. {
  155. // -MQBeg- [Op_Body] [CXVTTTTWin::ClearDisplay] <00000030.00000034> Retained!
  156.   WINDOW w = GetXVTWindow();
  157.   xvt_dwin_clear(w, COLOR_WHITE);
  158.   this->DrawGrid();
  159. // -MQEnd- [Op_Body] [CXVTTTTWin::ClearDisplay] <00000030.00000034> 
  160. }
  161.  
  162. void
  163. CXVTTTTWin::DisplayMove(int Row, int Col, char Move)
  164. {
  165. // -MQBeg- [Op_Body] [CXVTTTTWin::DisplayMove] <00000030.00000035> Retained!
  166.   WINDOW w = GetXVTWindow();
  167.   CRect r( this->GetRect(Row, Col).GetInflatedRect(-3) );
  168.  
  169.   // Erase the cell
  170.   xvt_dwin_set_std_cpen(w, TL_PEN_WHITE);
  171.   xvt_dwin_set_std_cbrush(w, TL_BRUSH_WHITE);
  172.   xvt_dwin_draw_rect( w, &RCT(r) );
  173.  
  174.   // Draw the move
  175.   PNT p;
  176.   r = r.GetInflatedRect(-2);
  177.   xvt_dwin_set_std_cpen(w, TL_PEN_BLACK);
  178.   switch (Move)
  179.   {
  180.   case 'O':
  181.     xvt_dwin_draw_oval( w, &RCT(r) );
  182.     break;
  183.   case 'X':
  184.     p.h=r.Left();  p.v=r.Top();    xvt_dwin_draw_set_pos(w, p);
  185.     p.h=r.Right(); p.v=r.Bottom(); xvt_dwin_draw_line(w, p);
  186.     p.h=r.Right(); p.v=r.Top();    xvt_dwin_draw_set_pos(w, p);
  187.     p.h=r.Left();  p.v=r.Bottom(); xvt_dwin_draw_line(w, p);
  188.     break;
  189.   }
  190. // -MQEnd- [Op_Body] [CXVTTTTWin::DisplayMove] <00000030.00000035> 
  191. }
  192.  
  193. CRect
  194. CXVTTTTWin::GetRect(int Row, int Col)
  195. {
  196. // -MQBeg- [Op_Body] [CXVTTTTWin::GetRect] <00000030.00000036> Retained!
  197.   int Left = BOARDXOFFSET + SW_SIZE * Col;
  198.   int Top  = BOARDYOFFSET + SW_SIZE * Row;
  199.   CRect r(Left, Top, Left+SW_SIZE-1, Top+SW_SIZE-1);
  200.   return r;
  201. // -MQEnd- [Op_Body] [CXVTTTTWin::GetRect] <00000030.00000036> 
  202. }
  203.  
  204. // -MQEnd- [Class_Body] [CXVTTTTWin] <00000000.00000013> 
  205.  
  206. // -MQBeg- [Module_Declarations_2] [cxvtttwn_cc] <00000028.00000000> Retained!
  207. // -MQEnd- [Module_Declarations_2] [cxvtttwn_cc] <00000028.00000000> 
  208.