-
Notifications
You must be signed in to change notification settings - Fork 0
/
CellByCellGameConfigurator.cpp
38 lines (34 loc) · 1.21 KB
/
CellByCellGameConfigurator.cpp
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
#include "CellByCellGameConfigurator.h"
#include <iostream>
/*
Manually adds an alive cell at the given position
*/
Error CellByCellGameConfigurator::addAliveCell(Position aliveCellPosition) {
if (aliveCellPosition.posX >= _fieldWidth ||
aliveCellPosition.posY >= _fieldHeight) {
return Error::InvalidPositionForCell;
}
_positions.push_back(aliveCellPosition);
return Error::None;
}
/*
Manually adds alive cells for each position provided in a vector
*/
void CellByCellGameConfigurator::batchAddAliveCells(const std::vector<Position>& aliveCells) {
for (const auto & aliveCell : aliveCells) {
if (addAliveCell(aliveCell) == Error::InvalidPositionForCell) {
std::cerr << "Alive cell with coordinates: " << aliveCell.posX << ", "
<< aliveCell.posY << " was not added: Out of field\n";
}
}
}
/*
Populates the given field using the internal vector of positions
with alive cells
*/
Error CellByCellGameConfigurator::populateField(Field & field) {
for (const auto & cellPosition : _positions) {
field.makeCellAlive(cellPosition.posX, cellPosition.posY);
}
return Error::None;
}