void COverlappedWindow::drawEdge(HDC paintDC, const RECT& rect, const Edge& e) {
	HBRUSH brush;
	HPEN pen;
	if (e.isFirstPlayer) {
		brush = ::CreateSolidBrush(getDrawInfo().firstPlayerColor);
		pen = ::CreatePen(PS_SOLID, getDrawInfo().lineStroke, getDrawInfo().firstPlayerColor);
	} else {
		brush = ::CreateSolidBrush(getDrawInfo().secondPlayerColor);
		pen = ::CreatePen(PS_SOLID, getDrawInfo().lineStroke, getDrawInfo().secondPlayerColor);
	}
	
	::SelectObject(paintDC, brush);
	::SelectObject(paintDC, pen);

	int indent = getDrawInfo().lineIndent;
	int x1 = (e.start.x + 1) * indent;
	int y1 = (e.start.y + 1)* indent;

	int x2 = (e.end.x + 1) * indent;
	int y2 = (e.end.y + 1) * indent;
	
	Line(paintDC, x1, y1, x2, y2);

	::DeleteObject(brush);
	::DeleteObject(pen);
}
void COverlappedWindow::setWindowSize() {
	int indent = getDrawInfo().lineIndent;
	int unexpectedXIndent = 20;
	int unexpectedYIndent = 65;
	int widthNumber = getGameInfo().widthGridNumber;
	int heightNumber = getGameInfo().heightGridNumber;
	int scoreboardSize = getDrawInfo().scoreboardSize;

	RECT rect;
	GetWindowRect(handle, &rect);
	int x = rect.left;
	int y = rect.top;

	::SetWindowPos(handle, 0, x, y,
		(widthNumber + 1) * indent + unexpectedXIndent,
		(heightNumber + 1) * indent + unexpectedYIndent + scoreboardSize, SWP_SHOWWINDOW);

}
void COverlappedWindow::drawScoreboard(HDC paintDC, const RECT& rect) {

	int indent = getDrawInfo().lineIndent;
	int y = indent * (getGameInfo().heightGridNumber + 1) + getDrawInfo().scoreboardSize / 3;
	int x = indent * (getGameInfo().widthGridNumber + 1) / 2;

	int firstScore = 0;
	int secondScore = 0;
	if (isGameStarted) {
		firstScore = game.getFirstResult();
		secondScore = game.getSecondResult();
	}

	std::string string = "First player " + std::to_string(firstScore) +
		":" + std::to_string(secondScore) + " Second player";
	std::wstring str = getWC(string.c_str());

	writeText(paintDC, getDrawInfo().scoreboardFont, x, y, str);
}
void COverlappedWindow::drawGrid(HDC paintDC, const RECT& rect) {
	HBRUSH brush = ::CreateSolidBrush(getDrawInfo().lineColor);
	HPEN pen = ::CreatePen(PS_SOLID, getDrawInfo().lineStroke, getDrawInfo().lineColor);
	::SelectObject(paintDC, pen);
	::SelectObject(paintDC, brush);

	int indent = getDrawInfo().lineIndent;
	int widthNumber = getGameInfo().widthGridNumber;
	int heightNumber = getGameInfo().heightGridNumber;
	for (int i = 0; i < widthNumber; ++i) {
		Line(paintDC, (i + 1) * indent, 0, (i + 1) * indent, (heightNumber + 1) * indent);
	}

	for (int i = 0; i < heightNumber; ++i) {
		Line(paintDC, 0, (i + 1) * indent, (widthNumber + 1) * indent, (i + 1) * indent);
	}

	::DeleteObject(brush);
	::DeleteObject(pen);
}
void Enemy::AvoidEntity(Player* p,std::vector<BaseGameEntity*> EMgr)
{
	//Zeroes out everything since movement possible failed
	//movement('n',p,EMgr);
	for(unsigned int i= 0;i<EMgr.size();i++)
	{
		//If the entity being checked is not itself, within sight range, and has not been tagged to stand still
		if(this != EMgr[i] && getDistance(this,EMgr[i]->getDrawInfo().hitBox) < AVOID_RANGE)
		{
			if(getDrawInfo().hitBox.right <= EMgr[i]->getDrawInfo().hitBox.right-5.0f)
				vel.x = -speed;
			if(getDrawInfo().hitBox.left >= EMgr[i]->getDrawInfo().hitBox.left+5.0f)
				vel.x = speed;
			if(getDrawInfo().hitBox.bottom >= EMgr[i]->getDrawInfo().hitBox.bottom-YRANGE_OFFSET)
				vel.y = speed;
			if(getDrawInfo().hitBox.top <= EMgr[i]->getDrawInfo().hitBox.top+YRANGE_OFFSET)
				vel.y = -speed;
		}
	}
}
void COverlappedWindow::drawPoint(HDC paintDC, const RECT& rect, int x_num, int y_num, PointState state) {
	HBRUSH brush;
	switch (state)
	{
	case FIRST_PLAYER:
		brush = ::CreateSolidBrush(getDrawInfo().firstPlayerColor);
		break;
	case SECOND_PLAYER:
		brush = ::CreateSolidBrush(getDrawInfo().secondPlayerColor);
		break;
	case INNER:
		brush = ::CreateSolidBrush(getDrawInfo().innerColor);
		break;
	case INNER_FIRST:
		brush = ::CreateSolidBrush(getDrawInfo().innerFirstColor);
		break;
	case INNER_SECOND:
		brush = ::CreateSolidBrush(getDrawInfo().innerSecondColor);
		break;
	default:
		brush = ::CreateSolidBrush(getDrawInfo().innerColor);
		break;
	}

	HPEN pen = ::CreatePen(PS_SOLID, getDrawInfo().lineStroke, getDrawInfo().playerPenColor);
	::SelectObject(paintDC, pen);
	::SelectObject(paintDC, brush);

	int indent = getDrawInfo().lineIndent;
	int radius = getDrawInfo().pointRadius;
	int x1 = (x_num + 1) * indent - radius;
	int y1 = (y_num + 1) * indent - radius;
	int x2 = (x_num + 1) * indent + radius;
	int y2 = (y_num + 1) * indent + radius;

	::Ellipse(paintDC, x1, y1, x2, y2);

	::DeleteObject(brush);
	::DeleteObject(pen);
}
bool Enemy::MovementPossible(std::vector<BaseGameEntity*> EMgr)
{
	for(unsigned int i=0;i<EMgr.size();++i)
	{
		if(this != EMgr[i] && EMgr[i]->isAlive())
		{
			if (getDrawInfo().hitBox.top >= EMgr[i]->getDrawInfo().hitBox.bottom-20 &&
			getDrawInfo().hitBox.top <= EMgr[i]->getDrawInfo().hitBox.top+20 &&
			getDrawInfo().hitBox.left >= EMgr[i]->getDrawInfo().hitBox.left+20 &&
			getDrawInfo().hitBox.left <= EMgr[i]->getDrawInfo().hitBox.right-20)
			{return false;}
			if (getDrawInfo().hitBox.right >= EMgr[i]->getDrawInfo().hitBox.left+20 &&
			getDrawInfo().hitBox.right <= EMgr[i]->getDrawInfo().hitBox.right-20 &&
			getDrawInfo().hitBox.bottom <= EMgr[i]->getDrawInfo().hitBox.top+20 &&
			getDrawInfo().hitBox.bottom >= EMgr[i]->getDrawInfo().hitBox.bottom-20)
			{return false;}
		}
	}
	return true;
}
void COverlappedWindow::OnLButtonDown(WPARAM wParam, LPARAM lParam) {
	if (!isPause) {
		POINT pos;
		GetCursorPos(&pos);
		ScreenToClient(handle, &pos);

		int indent = getDrawInfo().lineIndent;

		int x_num = abs(pos.x - indent / 2) / indent;
		int y_num = abs(pos.y - indent / 2) / indent;

		if (game.isInField(x_num, y_num) && game.markPoint(x_num, y_num, getGameInfo().isFirstNextStep)) {
			getGameInfo().isFirstNextStep = !getGameInfo().isFirstNextStep;
			isDoneFirstStep = true;
			game.buildGame();
		}

		::InvalidateRect(handle, 0, 0);
	}
}
void COverlappedWindow::drawBackground(HDC paintDC, const RECT& rect) {
	HBRUSH brush = CreateSolidBrush(getDrawInfo().backgroundColor);
	::FillRect(paintDC, &rect, brush);
	::DeleteObject(brush);
}