-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMovingObj.cpp
More file actions
112 lines (99 loc) · 3.59 KB
/
MovingObj.cpp
File metadata and controls
112 lines (99 loc) · 3.59 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include "MovingObj.h"
/*------------------------------------------------------------------------------------------------------------------------------------------------------------*/
//This method set a moving object to be with or without colors
void MovingObj::setMovingObjColor(bool _color)
{
color = _color;
}
/*------------------------------------------------------------------------------------------------------------------------------------------------------------*/
//This method sets a direction for the ghost's eyes.
void MovingObj::continueOldDir(const int& dir)
{
Eyes.move(dir, false);
}
/*------------------------------------------------------------------------------------------------------------------------------------------------------------*/
//This method prints the Ghost's figure on the board.
void MovingObj::drawMovingObj()
{
if (!silent)
{
if (color)
setTextColor(Color::LIGHTRED);
body.draw(figure);
}
}
/*------------------------------------------------------------------------------------------------------------------------------------------------------------*/
int MovingObj::updateEyes()
{
return Eyes.moveRandom();
}
/*------------------------------------------------------------------------------------------------------------------------------------------------------------*/
void MovingObj::setEyesLocation(int y, int x)
{
Eyes.setXY(y, x);
}
/*------------------------------------------------------------------------------------------------------------------------------------------------------------*/
void MovingObj::initLocation(const int& y, const int& x)
{
body.setXY(y, x);
Eyes.setXY(y, x);
}
/*------------------------------------------------------------------------------------------------------------------------------------------------------------*/
//This method updates the max values for a moving object.
void MovingObj::UpdateBorders(int _Maxrow, int MaxCol)
{
body.setMaxRow(_Maxrow);
Eyes.setMaxRow(_Maxrow);
body.setMaxCol(MaxCol);
Eyes.setMaxCol(MaxCol);
}
void MovingObj::moveMovingObj(char ch)
{
gotoxy(getMovingObjBodyX(), getMovingObjBodyY());
if(!silent)
cout << ch;
gotoxy(getMovingObjEyesX(), getMovingObjEyesY());
initLocation(getMovingObjEyesY(), getMovingObjEyesX());
drawMovingObj();
}
/*------------------------------------------------------------------------------------------------------------------------------------------------------------*/
//This method moves the index of the string forward.
void MovingObj::changePlace(int i)
{
place = i * place + i;
}
void MovingObj::addTime(int time)
{
moves += convertNum(time);
moves.push_back('.');
}
/*------------------------------------------------------------------------------------------------------------------------------------------------------------*/
//This method converts chars to a number.
string MovingObj::convertNum(int num)
{
string str;
while (num != 0)
{
string temp;
temp.push_back(num % 10 + '0');
str.insert(0, temp);
num /= 10;
}
return str;
}
/*------------------------------------------------------------------------------------------------------------------------------------------------------------*/
//This method fill the moves string.
void MovingObj::fillString(string& str)
{
moves.clear();
moves = str.substr(2, str.size() - 2);
}
/*------------------------------------------------------------------------------------------------------------------------------------------------------------*/
//This method reads a move from the string.
char MovingObj::readMove()
{
if (getPlace() < moves.size())
return moves[getPlace()];
else
return (int)Directions::STAY + '0';
}