:
Camera Camera, ;
Board Chessboard, ;
g_pDevice IDirect3DDevice9, ;
g_Matrix D3DXMATRIX, ;
:
hWnd ;
hResult HRESULT, .
, , | Figure |
King | |
Queen | |
Pawn | |
Bishop | |
Rook | |
Horse | |
Position | |
bvException | |
: | FriendlyFire |
: | EmptyCell |
: | BadMove |
: | BadDiagLine |
: | BadStraightLine |
: | NotUrTurn |
Camera | |
, Chessboard | Cell |
Chessboard |
Figure , , :
class Figure
{
protected:
std::string _sColor; // figure's color
public:
std::string GetColor(); // Method for receiving figure's color
void SetColor(std::string sColor); // Method for set figure's color
//
// abstract method for check if move is correct
//
virtual bool CheckMove(Cell& currentCell, Cell& nextCell) = 0;
//
// abstract method for draw figure
//
virtual void Draw(int material) = 0;
};
Cell , Chessboard
class Cell
{
Figure* _figure; // pointer to figure object
Pos _cPos; // cell's position
public:
Cell(int x, int y, Figure* figure); // constructor with parameters
Cell(); // default constructor
~Cell(); // destructor
Pos GetPos(); // method for receiving cell's position
Figure* GetFigure(); // method for receiving figure's pointer
void SetPos(Pos& cPos); // method for set cell's position (Pos&)
void SetPos(int x, int y); // method for set cell's position (int, int)
void SetFigure(Figure* figure); // method for set figure
bool MoveFigure(Cell& nextCell); // method for move figure to next cell
|
|
bool IsEmpty(); // method for check is cell is empty
std::string GetColor(); // method for receiving figure's color
void Draw(int material); // method for draw cell
};
Chessboard
class Chessboard
{
Figure* _WhitePawns;
Figure* _BlackPawns;
Figure* _WhiteKing;
Figure* _BlackKing;
Figure* _WhiteHorses;
Figure* _BlackHorses; // Figure pointers
Figure* _WhiteRooks;
Figure* _BlackRooks;
Figure* _WhiteBishops;
Figure* _BlackBishops;
Figure* _WhiteQueen;
Figure* _BlackQueen;
Cell _board[MAX_CELL_NUMBER][MAX_CELL_NUMBER]; // Matrix of cell object
int _iTurnCount; // int variable to choose player's turn
int _currentX; // int variable that mark on current cell
int _currentY; // int variable that mark on current cell
int _chosenX;
int _chosenY;
int _chosenNextX; // variables for making player's move
int _chosenNextY;
bool _isChosen;
public:
Chessboard(); // constructor
~Chessboard(); // destructor
void Move(int x, int y, int nx, int ny); // method for move figure
// method for draw chessboard
void Draw(D3DXMATRIX g_Matrix, IDirect3DDevice9* g_pDevice);
void IncX(); // method for increase current X coordinate
void IncY(); // method for increase current Y coordinate
void DecX(); // method for decrease current X coordinate
void DecY(); // method for decrease current Y coordinate
int GetCurrentX(); // method for receiving current X coordinate
int GetCurrentY(); // method for receiving current Y coordinate
void SetChosenX(int x); // method for set chosen X coordinate
void SetChosenY(int y); // method for set chosen Y coordinate
void SetChosenNextX(int nx); // method for set next chosen X coordinate
void SetChosenNextY(int ny); // method for set next chosen Y coordinate
void SetChosenFlag(bool flag); // method for set flag of chosen cell
bool GetChosenFlag(); // method for receiving flag of chosen cell
int GetChosenX(); // method for receiving chosen X coordinate
int GetChosenY(); // method for receiving chosen Y coordinate
int GetChosenNextX(); // method for receiving next chosen X coordinate
int GetChosenNextY(); // method for receiving next chosen Y coordinate
int GetTurnCount(); // method for receiving turn count
//
// method for check is striaght line is empty
//
bool CheckStraightLine(Cell& currentCell, Cell& nextCell);
//
// method for check is diagonal line is empty
//
bool CheckDiagLine(Cell& currentCell, Cell& nextCell);
};
-
6.1 bool MoveFigure(Cell& nextCell) Cell nextCell
6.2 int EnterMsgLoop(bool (*ptr_display) (float timeDelta))
7.1 void Draw(D3DXMATRIX g_Matrix, IDirect3DDevice9* g_pDevice) Chessboard :
1. .
2. :
_board ;
_currentX - , ;
_currentY Y- , ;
:
_board ;
3. Clear() IDirect3DDevice9.
|
|
4. BeginScene() IDirect3DDevice9.
5. y .
5.1. x .
5.1.1. D3DXMatrixTranslation() g_Matrix.
5.1.2. SetTransform() IDirect3DDevice9 g_Matrix.
5.1.3. _board[x][y] ,
5.1.3.1. x = _currentX y = _currentY,
5.1.3.1.1. Draw() , .
5.1.3.2. x ,
5.1.3.2.1. y ,
5.1.3.2.1.1. Draw() , .
5.1.3.2.2.
5.1.3.2.2.1. Draw() , .
5.1.3.3.
5.1.3.3.1. y ,
5.1.3.3.1.1. Draw() , .
5.1.3.3.2.
5.1.3.3.2.1. Draw() , .
5.1.4.
5.1.4.1. x = _currentX y = _currentY,
5.1.4.1.1. Draw , .
5.1.4.2. ,
5.1.4.2.1. Draw , .
5.1.4.3. ,
5.1.4.3.1. Draw , .
5.2. x.
6. .
7. EndScene() IDirect3DDevice9.
8. Present() IDirect3DDevice9.
9. .
7.2 bool CheckMove(Cell& currentCell, Cell& nextCell) Rook :
1. .
2. :
currentCell ;
nextCell ;
:
nextPos nextCell;
currentPos currentCell;
:
currentCell ;
nextCell ;
3. nextPos._x = currentPos._x nextPos._y = currentPos._y,
3.1. BadMove().
4. nextPos._x!= currentPos._x nextPos._y!= currentPos._y,
4.1. BadMove().
5. ,
5.1. ,
5.1.1. FriendlyFire().
6. .
7. .