1#include <Game/FruitManager.hpp>
2#include <Misc/Utils.hpp>
11 for (std::vector<Fruit>::iterator it = this->fruit.begin(); it != this->fruit.end();)
13 if (player->headHit((*it).x, (*it).y))
16 it = this->fruit.erase(it);
27 int diff = (this->amount - this->fruit.size());
30 for (
int i = 0; i < (diff); i++)
35 return (this->amount);
39 this->fruit.push_back(
Fruit(x, y));
53 }
while (player->
bodyHit(newx, newy) ||
54 board->
isWall(newx, newy));
56 this->
add(newx, newy);
58void FruitManager::draw(
Window* win)
60 for (
unsigned int i = 0; i < (this->fruit.size()); i++)
64 Colors::pair(COLOR_RED, COLOR_DEFAULT,
true));
A level where the snake runs and eats fruits.
bool isWall(int x, int y)
Tells if there's a wall at x y.
FruitManager(int amount)
Creates a Fruit container that has at most amount fruits at once on the screen.
void update(Player *player, Board *board)
Updates internal fruits, adding them to the board and making sure it doesn't touch player.
int getAmount()
Returns the maximum size we can store within this manager.
void add(int x, int y)
Creates a fruit, adding it at x, y.
void addRandomly(Board *board, Player *player)
Creates a fruit randomly within boundaries of board, making sure that it's not inside player.
bool eatenFruit(Player *player)
Tells if the player has eaten a fruit this frame.
bool bodyHit(int x, int y, bool isCheckingHead=false)
Tells if something at x and y collides with any part of the snake.
A segment of the terminal screen (2D char matrix).
void print(std::string str, int x, int y, ColorPair pair=0)
Shows text str at x y on the window with color pair.
int between(int min, int max)
Random number between min and max.