本文整理汇总了C++中Snake::getHeader方法的典型用法代码示例。如果您正苦于以下问题:C++ Snake::getHeader方法的具体用法?C++ Snake::getHeader怎么用?C++ Snake::getHeader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Snake
的用法示例。
在下文中一共展示了Snake::getHeader方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: foodEaten
/*
Checks if food has been eaten
*/
bool CollisionDetector::foodEaten(Snake snake, vector<Cell> &foodList)
{
Cell header = snake.getHeader();
//Iterates foodlist
for(int j = 0; j < foodList.size(); j++)
{
Cell foodCell = foodList.at(j);
//If header hits a food element, then clear foodlist and return
if(foodCell.getX() == header.getX() &&
foodCell.getY() == header.getY())
{
vector<Cell>::iterator i = foodList.begin() + j;
foodList.erase(i);
return true;
}
}
//No food eaten
return false;
}