-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboard.cpp
46 lines (38 loc) · 1.04 KB
/
board.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
39
40
41
42
43
44
45
46
#include "board.h"
void Board::removeSnake(const Snake& s) {
for (auto i = s.begin(); i != s.end(); ++i) {
vec[i->getY()/rows][i->getX()/cols] = EMPTY;
}
}
int Board::getRows() const {
return rows;
}
int Board::getCols() const {
return cols;
}
vector<placeholder>& Board::operator[](int index) {
if (index < 0 || index >= cols)
throw OutOfRange();
return vec[index];
}
vector<placeholder> Board::operator[](int index) const {
if (index < 0 || index >= cols)
throw OutOfRange();
return vec[index];
}
void Board::update(const Vertex& point, const placeholder& value) {
int x = point.getX() / jump, y = point.getY() / jump;
vec[x][y] = value;
}
vector<int> Board::generateNewFruit() {
int x = rand() % cols, y = rand() % rows;
while (vec[x][y] != placeholder::EMPTY) {
x = rand() % cols, y = rand() % rows;
}
vec[x][y] = FRUIT;
vector<int> coardinates {x, y};
return coardinates;
}
bool Board::checkRowsRange(int index) {
return index < rows && index >= 0;
}