Exemple #1
0
void			NcursesUI::draw(IGame const &game)
{
	int				color = 0;

	erase();
	// Draw background
	for (int x = _gameSize.first - 1; x >= 0; --x)
		for (int y = _gameSize.second - 1; y >= 0; --y)
			_drawChunk(x, y, (color = (x + y) % 3) + 13, '.');
	// Draw blocks
	for (auto *b : game.getBlocks())
		_drawChunk(b->getX(), b->getY(), 20 + b->getType(), '+' + b->getType());
	// Draw snake
	for (auto &c : game.getSnake().getChunks())
		_drawChunk(c.first, c.second, 2, 'X');
	if (game.getSnake().isDie())
	{
		auto &head = *(game.getSnake().getChunks().begin());
		_drawChunk(head.first, head.second, 3, 'x');
	}
	attron(COLOR_PAIR(1));
	move(0, 0);
	printw("Score: %-3d Time: %-3d Length: %-3d FPS: %d",
		game.getScore(), game.getPlayTime(),
		game.getSnake().getChunks().size(), game.getFPS());
	if (game.getSnake().isDie())
		printw("  [[ DIE ]]");
	else if (game.isPaused())
		printw("  [[ PAUSE ]]");
	refresh();
}
Exemple #2
0
void                        OpenGLUI::_putTexts(IGame const &game)
{
	int const		fontSize(_winSize.first / 19);
	double const	padding(static_cast<double>(_winSize.first) / 19.);
	double const	timeWidth(static_cast<double>(_winSize.first) / 19. * 8.);
	double const	pausePadding(
		(static_cast<double>(_winSize.first) -
		 static_cast<double>(_winSize.first) / 19. * 4.) / 2.);

	this->_font.FaceSize(fontSize);
	this->_font.Render(
		(std::string("Score: ") += std::to_string(game.getScore())).c_str(),
		-1, FTPoint(padding, padding));
	this->_font.Render(
		(std::string("Played: ")
		 += std::to_string(game.getPlayTime() / 60)
		 += std::string(":")
		 += std::string(game.getPlayTime() % 60 > 9 ? "" : "0")
		 += std::to_string(game.getPlayTime() % 60)).c_str(),
		-1, FTPoint(static_cast<double>(_winSize.first) - timeWidth - padding,
					padding));
	if (game.getSnake().isDie())
	{
		this->_font.Render(
			std::string("Death!!").c_str(), -1,
			FTPoint(pausePadding, static_cast<double>(_winSize.second) / 2.));		
	}
	else if (game.isPaused())
	{
		this->_font.Render(
			std::string("Paused").c_str(), -1,
			FTPoint(pausePadding, static_cast<double>(_winSize.second) / 2.));
	}
	return ;
}