-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstructs.h
130 lines (114 loc) · 2.57 KB
/
structs.h
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#ifndef STRUCTS_H
#define STRUCTS_H
#include <iostream>
#include <cmath>
using namespace std;
struct Coords
{
int i;
int j;
};
int operator==(const Coords& c1, const Coords& c2) {
return c1.i == c2.i && c1.j == c2.j;
}
int operator<(const Coords&c1, const Coords& c2){
return c1.i < c2.i && c1.j < c2.j;
}
int operator>(const Coords&c1, const Coords& c2){
return c1.i > c2.i && c1.j > c2.j;
}
void setTime(int &scatterTime, int &chaseTime, int choosenLevel){
if(choosenLevel == 1){
scatterTime = 10;
chaseTime = 200;
}
else if(choosenLevel == 2){
scatterTime = 150;
chaseTime = 100;
}
else{
scatterTime = 150;
chaseTime = 150;
}
}
bool isThereWall(int **arr, Coords coords, char direction){
// cout << "XXX: " << coords.i << " " << coords.j << endl;
switch (direction)
{
case 'w':
if(arr[coords.i - 1][coords.j] == 1){
return true;
}
return false;
break;
case 's':
if(arr[coords.i + 1][coords.j] == 1){
return true;
}
return false;
break;
case 'd':
if(arr[coords.i][coords.j + 1] == 1){
return true;
}
return false;
break;
case 'a':
if(arr[coords.i][coords.j - 1] == 1){
return true;
}
return false;
break;
}
}
bool isThereCherry(int **arr, Coords coords, char direction){
switch (direction)
{
case 'w':
if(arr[coords.i - 1][coords.j] == 3){
return true;
}
return false;
break;
case 's':
if(arr[coords.i + 1][coords.j] == 3){
return true;
}
return false;
break;
case 'd':
if(arr[coords.i][coords.j + 1] == 3){
return true;
}
return false;
break;
case 'a':
if(arr[coords.i][coords.j - 1] == 3){
return true;
}
return false;
break;
}
}
bool ghostCheck(Coords pacman, Coords ghost){
Coords minCoor;
int dist = 0, xDist, yDist;
xDist = (ghost.i - pacman.i)* (ghost.i - pacman.i);
yDist = (ghost.j - pacman.j) * (ghost.j - pacman.j);
dist = sqrt(xDist + yDist);
if(dist <= 1){
return true;
}
return false;
}
int calScore(int dotCounter, int ghostCounter, int cherryCounter){
int score = 0;
cherryCounter *= 5;
for(int i = 1; i <= ghostCounter; i++){
score += i * 10;
}
score += dotCounter;
score += cherryCounter;
return score;
}
#endif