本文整理汇总了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;
}
示例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;
}