コード例 #1
0
ファイル: NcursesUI.cpp プロジェクト: Julow/Nibbler
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();
}