-
Notifications
You must be signed in to change notification settings - Fork 0
/
Render.cpp
47 lines (42 loc) · 1.28 KB
/
Render.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <map>
#include "Render.h"
namespace mnkgame
{
void Render::draw(DrawVariables* dw)
{
if (m_engine == nullptr)
return;
drawBoard(dw, m_engine->getBoard().getRows(), m_engine->getBoard().getCols());
drawPosition(dw);
if (m_engine->getGameState() == GameState::GAME_OVER)
{
// draw the win line over the winners pieces
static const std::map<WinDir, Coordinate> s_winDir{ { WinDir::EAST, {0,1} }, { WinDir::SOUTH, {1,0} },
{ WinDir::SOUTH_EAST, {1,1} }, { WinDir::SOUTH_WEST, {1,-1} } };
PosInfo winInfo = m_engine->getGameOverInfo();
Coordinate coordStart, coordEnd;
coordStart = winInfo.winpos;
coordEnd = { coordStart.x + s_winDir.at(winInfo.windir).x * (m_engine->getWinRowLenght() - 1),
coordStart.y + s_winDir.at(winInfo.windir).y * (m_engine->getWinRowLenght() - 1) };
drawWinLine(dw, coordStart, coordEnd);
}
}
void Render::drawPosition(DrawVariables* dw)
{
if (m_engine == nullptr)
return;
int rows, cols;
rows = m_engine->getBoard().getRows();
cols = m_engine->getBoard().getCols();
for (int i = 0; i < rows; ++i)
{
for (int j = 0; j < cols; ++j)
{
if (m_engine->getBoard().getSquareValue({ i, j }) == Player::X)
drawX(dw, { i, j });
else if (m_engine->getBoard().getSquareValue({ i, j }) == Player::O)
drawO(dw, { i, j });
}
}
}
}