-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFruit.cpp
More file actions
61 lines (56 loc) · 1.88 KB
/
Fruit.cpp
File metadata and controls
61 lines (56 loc) · 1.88 KB
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
57
58
59
60
61
#include "Fruit.h"
/*------------------------------------------------------------------------------------------------------------------------------------------------------------*/
//This method sets the figure of a fruit.
Fruit::Fruit(bool _silent) :MovingObj(_silent)
{
int digit;
digit = rand() % 5;
figure =(digit + '5');
}
/*------------------------------------------------------------------------------------------------------------------------------------------------------------*/
//This method moves the fruit on the board.
void Fruit::moveMovingObj(char ch)
{
if (color)
setTextColor(Color::WHITE);
MovingObj::moveMovingObj(ch);
}
/*------------------------------------------------------------------------------------------------------------------------------------------------------------*/
//This method write the coordinates of the fruit to the a string.
void Fruit::addCoord(int y, int x)
{
moves += convertNum(y);
moves.push_back(',');
moves += convertNum(x);
moves.push_back(',');
}
/*------------------------------------------------------------------------------------------------------------------------------------------------------------*/
//This method read the coordinate of the fruit from the txt file.
int Fruit::readCoord()
{
int coord = 0;
char temp = readMove();
while (temp != ',')
{
coord = 10 * coord + (temp - '0');
changePlace();
temp = readMove();
}
changePlace();
return coord;
}
/*------------------------------------------------------------------------------------------------------------------------------------------------------------*/
//This method read the time of the fruit's revive from the txt file.
void Fruit::writeTimeTo()
{
int timeTo = 0;
char temp = readMove();
while (temp != '.' &&temp != 'k' && place != moves.size())
{
timeTo = 10 * timeTo + (temp - '0');
changePlace();
temp = readMove();
}
changePlace();
timeToApear = timeTo;
}