-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWorld.h
53 lines (46 loc) · 1.85 KB
/
World.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/**
* @file World.h
* @brief Defines the World class which manages a 2D grid of Organism objects.
*
* @class World
*
* @details World is managed via various public methods, with access provided
* to Organism, Predator and Prey. It includes grid access, display functionality,
* and simulation step methods. The size of the grid is defined by the private constant WORLDSIZE.
*/
#ifndef WORLD_H
#define WORLD_H
#include <vector>
// These are forward declarations; they are used because World uses pointers to these classes, but does not need to know their internal details.
class Organism;
class Predator;
class Prey;
class World
{
friend class Organism;
friend class Predator;
friend class Prey;
std::vector<Organism*> Predators;
std::vector<Organism*> NewPredators;
std::vector<Organism*> Preys;
std::vector<Organism*> NewPreys;
public:
World();
~World();
Organism* getAt(int x, int y);
void setAt(int x, int y, Organism *org); // If organism is predator, add to Predators vector. If organism is prey, add to Preys vector.
void Display();
void SimulateOneStep(); // First call simulateOneStepPredators, then simulateOneStepPreys
void pushPredator(Organism* pred); // Adds predator to Predators vector
void pushPrey(Organism* prey); // Adds prey to Preys vector
void removePredator(Organism* pred); // Removes predator from Predators vector
void removePrey(Organism* prey); // Removes prey from Preys vector
void SimulateOneStepPredators(); // Simulates one step for all predators
void SimulateOneStepPreys(); // Simulates one step for all preys
void InitializeGame(); // Initializes the game by user inputting an amount of predators and preys
void GameLoop(); // Runs the game loop
private:
static constexpr int WORLDSIZE = 30;
Organism* grid[WORLDSIZE][WORLDSIZE];
};
#endif // WORLD_H