当前位置: 首页>>代码示例>>C++>>正文


C++ Snake::affect方法代码示例

本文整理汇总了C++中Snake::affect方法的典型用法代码示例。如果您正苦于以下问题:C++ Snake::affect方法的具体用法?C++ Snake::affect怎么用?C++ Snake::affect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Snake的用法示例。


在下文中一共展示了Snake::affect方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: play

void Game::play() {
	bool isGameOver = false;
	bool isBomb = false;
	bool isAppleEaten = true;
	bool isSurpriseEaten = false; // doda dopiero po pierwszych 50 odœwie¿eniach
	bool isAffected = false;
	int randomX = 4, randomY = 4, randomX2 = 4, randomY2 = 4, randomSurprise = 1, timeCounter = 0, roundTime = 100, surpriseTime = 50;
	Snake *snake = this->player->getSnake();
	snake->setupSnake(board, snake->getHeadX(), snake->getHeadY());
	char input;
	bool ifPause = false;
	bool isSurprise = true;
	int affectNumber = 0;
	//display loop

	this->graphics->music();

	

	do {
		if (isAffected) {
			Surprise *surprise = board->getField(snake->getHeadX(), snake->getHeadY())->getSurprise();
			if (snake->affect(surprise, affectNumber, isBomb, isAppleEaten, isSurpriseEaten)) {
				board->getField(snake->getHeadX(), snake->getHeadY())->removeSurprise();
			}
			isAffected = false;
		}

		// setting random surpise (Banana or Bomb) at random GameField
		if (timeCounter == surpriseTime) {
			if (board->getField(randomX2, randomY2)->isSurprise()) {
				board->getField(randomX2, randomY2)->removeSurprise();
			}

			do {
				srand(time(NULL));
				randomX2 = (rand() + 123) % 23 + 2; // ¿eby siê randomki ró¿ni³y bo inaczej siê nadpisuj¹, trzbea pomyœleæ czy mo¿na inaczej 
				randomY2 = (rand() + 243) % 23 + 2;
				randomSurprise = rand() % 2 + 1;
			} while (board->getField(randomX2, randomY2)->isSurprise() || !board->getField(randomX2, randomY2)->isEmpty()); // ma losowaæ dopóki JEST niespodzianka! lub pole nie jest empty
			board->getField(randomX2, randomY2)->setSurprise(randomSurprise);
			isSurpriseEaten = false;
			timeCounter = 0;
		}

		if (isAppleEaten) {
			do {
				srand(time(NULL));
				randomX = rand() % 23 + 2;
				randomY = rand() % 23 + 2;
			} while (!board->getField(randomX, randomY)->isEmpty());
			board->getField(randomX, randomY)->setSurprise(3);
			isAppleEaten = false;
		}

		timeCounter++;


		/*gotoxy(0, 0);
		cout << endl << "SCORE: " << player->getSnake()->getLength() << endl;
		board->display();*/


		//GUI DISPLAY
		this->graphics->draw(750, 950, this->board);
		this->graphics->drawName(player->getName().c_str());
		this->graphics->drawScore(player->getSnake()->getLength());
		this->graphics->presentGraphics();

		/// moving of snake
		if (_kbhit()) {
			input = _getch();
		if (input == 'p') {
				ifPause = true;
				this->graphics->pauseWindow();
				this->graphics->presentGraphics();
				this->graphics->haltMusic();
				do {
					if (_kbhit()) {
						input = _getch();
						if (input == 'p') {
							ifPause = false;
							this->graphics->resumeMusic();
						}
					}
				} while (ifPause);
			}
			snake->setDirection(input);
		}
		else {
			snake->setDirection(snake->getDirection());
		}


		/// checking if snake reached a surprise
		if (board->getField(snake->getHeadX(), snake->getHeadY())->isSurprise()) {
			isAffected = true;
			this->graphics->playSoundEffect1();
		}

//.........这里部分代码省略.........
开发者ID:kamilglonek,项目名称:snakeGame,代码行数:101,代码来源:Game.cpp


注:本文中的Snake::affect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。