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


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

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


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

示例1: performGameRuntimeChecks

/*
Method is responsible for runtime checks:
	- Collision detection
	- Food eaten
	- Drawing
	Return(true) -> GameOver
	Return(false)-> Keep running
*/
bool GameController::performGameRuntimeChecks(CInputManager &inputManager,
											  unsigned long &score, CollisionDetector &collisionDetector,
											  DrawEngine drawEngine, int key, Snake &snake, vector<Cell> &foodList,
											  FoodProvider &foodProvider, Cell lastCell)
{
	//If collision detected
	if(collisionDetector.collisionDetected(snake))
	{
		char message[] = "GAME OVER! <Press any key>";
		drawEngine.showMessage(message);
		inputManager.GetNextKeyWait(&key);
		return true;
	}
	//Food eaten
	else if(collisionDetector.foodEaten(snake, foodList))
	{
		//Setting new score
		score += snake.getCells().size()*2;
		//Draw score
		drawEngine.updateScore(score);
		//Add cell
		snake.addCell();
		//Recieving new foodList
		vector<Cell> &list = foodProvider.provideFood(snake, drawEngine.getWindownWidth(), 
			drawEngine.getMenuBorderHeight());
		foodList = list;
	}
	//Draw snake
	drawEngine.drawSnake(snake, lastCell);
	//Draw food
	drawEngine.drawFood(foodList);
	return false;
}
开发者ID:sangar,项目名称:Snake,代码行数:41,代码来源:GameController.cpp

示例2: collisionDetected

/*
Detects if snake hits a wall or itself
*/
bool CollisionDetector::collisionDetected(Snake snake)
{
	Cell header = snake.getHeader();
	int x = header.getX();
	int y = header.getY();
	//Iteration snakes cells, detecting self hit
	for(int i = 1; i < snake.getCells().size(); i++)
	{
		Cell currCell = snake.getCells().at(i);
		if(currCell.getX() == x && currCell.getY() == y)
			return true;
	}
	if(x >= width || y >= height || x < 0 || y < 0)
		return true;
	return false;
}
开发者ID:sangar,项目名称:Snake,代码行数:19,代码来源:CollisionDetector.cpp


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