-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPoint.cpp
More file actions
75 lines (67 loc) · 1.54 KB
/
Point.cpp
File metadata and controls
75 lines (67 loc) · 1.54 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
#include "Point.h"
/*------------------------------------------------------------------------------------------------------------------------------------------------------------*/
//This method draws a shape.
void Point::draw(char ch)const
{
gotoxy(x, y);
cout << ch << endl;
}
/*------------------------------------------------------------------------------------------------------------------------------------------------------------*/
//This method moves the ghost randomly.
int Point::moveRandom()
{
int dir = rand() % 4;
move(dir, false);
return dir;
}
/*------------------------------------------------------------------------------------------------------------------------------------------------------------*/
//This method translates a direction to a new coordinate.
void Point::move(int direction, bool flag)
{
switch (direction) {
case (int)Directions::UP:
--y;
if (flag == true)
{
if (y < minRow) {
y = maxRow ;
}
}
break;
case (int)Directions::DOWN:
++y;
if (flag == true)
{
if (y > maxRow ) {
y = minRow;
}
}
break;
case (int)Directions::LEFT:
--x;
if (flag == true)
{
if (x < 0) {
x = maxCol - 1;
}
}
break;
case (int)Directions::RIGHT:
++x;
if (flag == true)
{
if (x > maxCol - 1) {
x = 0;
}
}
break;
case (int)Directions::STAY:
break;
}
}
/*------------------------------------------------------------------------------------------------------------------------------------------------------------*/
void Point::setXY(int _y, int _x)
{
y = _y;
x = _x;
}