home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
scase.zip
/
SCASE.Z
/
CXVTTTWN.CC
< prev
next >
Wrap
C/C++ Source or Header
|
1994-10-17
|
7KB
|
208 lines
/******************************************************************************
* ** Company Confidential **
* ** Copyright 1994, All rights Reserved **
* %Z%%M% version %I% date:%G%
******************************************************************************/
// -MQBeg- [Module_Includes] [cxvtttwn_cc] <00000028.00000000> Retained!
#include "PwrDef.h"
#include "AppDef.h"
#include CTypeInfo_i
#include CDocument_i
#include CWindow_i
#include "ttteng.h"
#include "tttdisp.h"
#include "tttcont.h"
#include XVTTTT_i
#include CXVTTTTDoc_i
#include CXVTTTTWin_i
// -MQEnd- [Module_Includes] [cxvtttwn_cc] <00000028.00000000>
// -MQBeg- [Module_Declarations_1] [cxvtttwn_cc] <00000028.00000000> Retained!
// -MQEnd- [Module_Declarations_1] [cxvtttwn_cc] <00000028.00000000>
// -MQBeg- [Class_Body] [CXVTTTTWin] <00000000.00000013>
/******************************************************************************
CXVTTTTWin
******************************************************************************/
CXVTTTTWin::CXVTTTTWin(TTT_Engine *Engine, CDocument *theDocument, const CRect& theRegion, const CStringRW& theTitle , long theWindowAttributes, WIN_TYPE theWindowType, int theMenuBarId)
// -MQBeg- [Op_Init] [CXVTTTTWin::CXVTTTTWin] <00000030.00000029> Retained!
: TTT_Display(Engine), TTT_Controller(Engine, this),
CWindow(theDocument, theRegion, theTitle,
theWindowAttributes, theWindowType, theMenuBarId)
// -MQEnd- [Op_Init] [CXVTTTTWin::CXVTTTTWin] <00000030.00000029>
{
// -MQBeg- [Op_Body] [CXVTTTTWin::CXVTTTTWin] <00000030.00000029> Retained!
// -MQEnd- [Op_Body] [CXVTTTTWin::CXVTTTTWin] <00000030.00000029>
}
CXVTTTTWin::~CXVTTTTWin()
{
// -MQBeg- [Op_Body] [CXVTTTTWin::~CXVTTTTWin] <00000030.0000002A> Retained!
theDisplay = NULL; // So that the base class does not delete this!!
// -MQEnd- [Op_Body] [CXVTTTTWin::~CXVTTTTWin] <00000030.0000002A>
}
void
CXVTTTTWin::DisplayWelcomeMsg()
{
// -MQBeg- [Op_Body] [CXVTTTTWin::DisplayWelcomeMsg] <00000030.0000002B> Retained!
xvt_dm_post_note("Welcome to Tic Tac Toe");
// -MQEnd- [Op_Body] [CXVTTTTWin::DisplayWelcomeMsg] <00000030.0000002B>
}
void
CXVTTTTWin::DisplayIllegalMove()
{
// -MQBeg- [Op_Body] [CXVTTTTWin::DisplayIllegalMove] <00000030.0000002C> Retained!
xvt_scr_beep();
// -MQEnd- [Op_Body] [CXVTTTTWin::DisplayIllegalMove] <00000030.0000002C>
}
void
CXVTTTTWin::DisplayYouWin()
{
// -MQBeg- [Op_Body] [CXVTTTTWin::DisplayYouWin] <00000030.0000002D> Retained!
xvt_dm_post_note("You win!");
// -MQEnd- [Op_Body] [CXVTTTTWin::DisplayYouWin] <00000030.0000002D>
}
void
CXVTTTTWin::DisplayYouLose()
{
// -MQBeg- [Op_Body] [CXVTTTTWin::DisplayYouLose] <00000030.0000002E> Retained!
xvt_dm_post_note("You lose!");
// -MQEnd- [Op_Body] [CXVTTTTWin::DisplayYouLose] <00000030.0000002E>
}
void
CXVTTTTWin::DisplayDraw()
{
// -MQBeg- [Op_Body] [CXVTTTTWin::DisplayDraw] <00000030.0000002F> Retained!
xvt_dm_post_note("It's a draw!");
// -MQEnd- [Op_Body] [CXVTTTTWin::DisplayDraw] <00000030.0000002F>
}
void
CXVTTTTWin::DrawGrid()
{
// -MQBeg- [Op_Body] [CXVTTTTWin::DrawGrid] <00000030.00000030> Retained!
PNT p;
WINDOW w = GetXVTWindow();
xvt_dwin_set_std_cpen(w, TL_PEN_BLACK);
p.h=BOARDXOFFSET+SW_SIZE; p.v=BOARDYOFFSET; xvt_dwin_draw_set_pos(w, p);
p.h=BOARDXOFFSET+SW_SIZE; p.v=BOARDYOFFSET+(SW_SIZE*3); xvt_dwin_draw_line(w, p);
p.h=BOARDXOFFSET+(SW_SIZE*2); p.v=BOARDYOFFSET; xvt_dwin_draw_set_pos(w, p);
p.h=BOARDXOFFSET+(SW_SIZE*2); p.v=BOARDYOFFSET+(SW_SIZE*3); xvt_dwin_draw_line(w, p);
p.h=BOARDXOFFSET; p.v=BOARDYOFFSET+SW_SIZE; xvt_dwin_draw_set_pos(w, p);
p.h=BOARDXOFFSET+(SW_SIZE*3); p.v=BOARDYOFFSET+SW_SIZE; xvt_dwin_draw_line(w, p);
p.h=BOARDXOFFSET; p.v=BOARDYOFFSET+(SW_SIZE*2); xvt_dwin_draw_set_pos(w, p);
p.h=BOARDXOFFSET+(SW_SIZE*3); p.v=BOARDYOFFSET+(SW_SIZE*2); xvt_dwin_draw_line(w, p);
// -MQEnd- [Op_Body] [CXVTTTTWin::DrawGrid] <00000030.00000030>
}
void
CXVTTTTWin::Draw(const CRect& /*theClippingRegion*/ )
{
// -MQBeg- [Op_Body] [CXVTTTTWin::Draw] <00000030.00000031> Retained!
this->HandleEvent(TTT_Controller::UPDATE);
// -MQEnd- [Op_Body] [CXVTTTTWin::Draw] <00000030.00000031>
}
void
CXVTTTTWin::DoMouseDown(CPoint theLocation, short /*theButton*/, BOOLEAN /*isShiftKey*/, BOOLEAN /*isControlKey*/)
{
// -MQBeg- [Op_Body] [CXVTTTTWin::DoMouseDown] <00000030.00000032> Retained!
for (int Row=0; Row<3; Row++)
for (int Col=0; Col<3; Col++)
{
CRect r( this->GetRect(Row, Col) );
if ( r.IsPointInRect(theLocation) )
{
this->HandleEvent(TTT_Controller::MOVE, Row*3+Col);
return;
}
}
// -MQEnd- [Op_Body] [CXVTTTTWin::DoMouseDown] <00000030.00000032>
}
void
CXVTTTTWin::DoMenuCommand(MENU_TAG theMenuItem, BOOLEAN isShiftKey, BOOLEAN isControlKey)
{
// -MQBeg- [Op_Body] [CXVTTTTWin::DoMenuCommand] <00000030.00000033> Retained!
switch (theMenuItem)
{
case MENU_GAME_RESET:
this->HandleEvent(TTT_Controller::RESET);
break;
default:
CWindow::DoMenuCommand(theMenuItem, isShiftKey, isControlKey);
break;
}
// -MQEnd- [Op_Body] [CXVTTTTWin::DoMenuCommand] <00000030.00000033>
}
void
CXVTTTTWin::ClearDisplay()
{
// -MQBeg- [Op_Body] [CXVTTTTWin::ClearDisplay] <00000030.00000034> Retained!
WINDOW w = GetXVTWindow();
xvt_dwin_clear(w, COLOR_WHITE);
this->DrawGrid();
// -MQEnd- [Op_Body] [CXVTTTTWin::ClearDisplay] <00000030.00000034>
}
void
CXVTTTTWin::DisplayMove(int Row, int Col, char Move)
{
// -MQBeg- [Op_Body] [CXVTTTTWin::DisplayMove] <00000030.00000035> Retained!
WINDOW w = GetXVTWindow();
CRect r( this->GetRect(Row, Col).GetInflatedRect(-3) );
// Erase the cell
xvt_dwin_set_std_cpen(w, TL_PEN_WHITE);
xvt_dwin_set_std_cbrush(w, TL_BRUSH_WHITE);
xvt_dwin_draw_rect( w, &RCT(r) );
// Draw the move
PNT p;
r = r.GetInflatedRect(-2);
xvt_dwin_set_std_cpen(w, TL_PEN_BLACK);
switch (Move)
{
case 'O':
xvt_dwin_draw_oval( w, &RCT(r) );
break;
case 'X':
p.h=r.Left(); p.v=r.Top(); xvt_dwin_draw_set_pos(w, p);
p.h=r.Right(); p.v=r.Bottom(); xvt_dwin_draw_line(w, p);
p.h=r.Right(); p.v=r.Top(); xvt_dwin_draw_set_pos(w, p);
p.h=r.Left(); p.v=r.Bottom(); xvt_dwin_draw_line(w, p);
break;
}
// -MQEnd- [Op_Body] [CXVTTTTWin::DisplayMove] <00000030.00000035>
}
CRect
CXVTTTTWin::GetRect(int Row, int Col)
{
// -MQBeg- [Op_Body] [CXVTTTTWin::GetRect] <00000030.00000036> Retained!
int Left = BOARDXOFFSET + SW_SIZE * Col;
int Top = BOARDYOFFSET + SW_SIZE * Row;
CRect r(Left, Top, Left+SW_SIZE-1, Top+SW_SIZE-1);
return r;
// -MQEnd- [Op_Body] [CXVTTTTWin::GetRect] <00000030.00000036>
}
// -MQEnd- [Class_Body] [CXVTTTTWin] <00000000.00000013>
// -MQBeg- [Module_Declarations_2] [cxvtttwn_cc] <00000028.00000000> Retained!
// -MQEnd- [Module_Declarations_2] [cxvtttwn_cc] <00000028.00000000>