nsnake
Classic snake game for the terminal
Toggle main menu visibility
Loading...
Searching...
No Matches
src
Game
FruitManager.hpp
1
#ifndef FRUITMANAGER_H_DEFINED
2
#define FRUITMANAGER_H_DEFINED
3
4
#include <Game/Player.hpp>
5
#include <Game/Board.hpp>
6
#include <Interface/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
22
class
FruitManager
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
Board
A level where the snake runs and eats fruits.
Definition
Board.hpp:33
FruitManager::FruitManager
FruitManager(int amount)
Creates a Fruit container that has at most amount fruits at once on the screen.
Definition
FruitManager.cpp:4
FruitManager::update
void update(Player *player, Board *board)
Updates internal fruits, adding them to the board and making sure it doesn't touch player.
Definition
FruitManager.cpp:24
FruitManager::getAmount
int getAmount()
Returns the maximum size we can store within this manager.
Definition
FruitManager.cpp:33
FruitManager::add
void add(int x, int y)
Creates a fruit, adding it at x, y.
Definition
FruitManager.cpp:37
FruitManager::addRandomly
void addRandomly(Board *board, Player *player)
Creates a fruit randomly within boundaries of board, making sure that it's not inside player.
Definition
FruitManager.cpp:41
FruitManager::eatenFruit
bool eatenFruit(Player *player)
Tells if the player has eaten a fruit this frame.
Definition
FruitManager.cpp:7
Player
Definition
Player.hpp:24
Window
A segment of the terminal screen (2D char matrix).
Definition
Window.hpp:17
Generated on
for nsnake by
1.17.0