-
Notifications
You must be signed in to change notification settings - Fork 3
/
Fruit.cpp
56 lines (45 loc) · 1.06 KB
/
Fruit.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
47
48
49
50
51
52
53
54
55
56
#include "Header.hpp"
//#include "Fruit.hpp"
Fruit::Fruit()
{
this->fruit_position = find_position();
this->x = System::set_x(fruit_position);
this->y = System::set_y(fruit_position);
}
int Fruit::find_position()
{
int fruit_position = Map::canvas.find(FRUIT);
Map::canvas.replace(fruit_position, 1, " ");
return fruit_position;
}
int Fruit::get_position()
{
return fruit_position;
}
void Fruit::generate_position()
{
int new_fruit_position;
int fruit_x_position;
int fruit_y_position;
do
{
new_fruit_position = System::generate_ramdom_number() % Map::canvas.length();
} while (Map::canvas.at(new_fruit_position) != ' ');
this->x = new_fruit_position % Map::get_width();
this->y = new_fruit_position / Map::get_width();
this->fruit_position = new_fruit_position;
}
void Fruit::draw()
{
System::gotoxy(x, y);
cout << YELLOW_CHAR << FRUIT << RESET_COLOR_SCHEME;
}
std::tuple<int, int> Fruit::get_coord()
{
return tie(x, y);
}
void Fruit::generate()
{
generate_position();
draw();
}