nsnake
Classic snake game for the terminal
FruitManager.hpp
1 #ifndef FRUITMANAGER_H_DEFINED
2 #define FRUITMANAGER_H_DEFINED
3 
4 #include <Entities/Player.hpp>
5 #include <Entities/Board.hpp>
6 #include <Engine/Graphics/Window.hpp>
7 
8 #include <vector>
9 
11 struct Fruit
12 {
13  int x;
14  int y;
15  Fruit(int x, int y):
16  x(x),
17  y(y)
18  { }
19 };
20 
23 {
24 public:
27  FruitManager(int amount);
28 
29  virtual ~FruitManager() {};
30 
32  bool eatenFruit(Player* player);
33 
36  void update(Player* player, Board* board);
37 
44  int getAmount();
45 
48  void add(int x, int y);
49 
54  void addRandomly(Board* board, Player* player);
55 
56  void draw(Window* win);
57 
58 private:
59  std::vector<Fruit> fruit;
60  int amount;
61 };
62 
63 #endif //FRUITMANAGER_H_DEFINED
64 
void add(int x, int y)
Creates a fruit, adding it at #x, #y.
bool eatenFruit(Player *player)
Tells if the #player has eaten a fruit this frame.
Definition: FruitManager.cpp:8
A single fruit.
Controls how many Fruits are there and how they're spawned.
void update(Player *player, Board *board)
Updates internal fruits, adding them to the #board and making sure it doesn't touch #player.
A level where the snake runs and eats fruits.
Definition: Board.hpp:32
int getAmount()
Returns the maximum size we can store within this manager.
void addRandomly(Board *board, Player *player)
Creates a fruit randomly within boundaries of #board, making sure that it's not inside #player.
FruitManager(int amount)
Creates a Fruit container that has at most #amount fruits at once on the screen.
Definition: FruitManager.cpp:5