forked from annatruong04/project_oop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBallom.cpp
29 lines (28 loc) · 953 Bytes
/
Ballom.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
#include "Ballom.h"
#include "Move.h"
Ballom::Ballom(int Px, int Py, int Pox, int Poy): Animal(Px, Py, Pox, Poy) {};
void Ballom::update() {
// Check if the Ballom's position is aligned with the grid
if (this->getPoy() % 16 == 0 && this->getPox() % 16 == 0) {
// Generate a random number between 0 and 3 to determine Ballom's next move
int random = rand()%4;
switch (random) {
// move down if the random number is 0
case 0:
Move::down(this);
break;
// move up if the random number is 1
case 1:
Move::up(this);
break;
// move to the left if the random number is 2
case 2:
Move::left(this);
break;
// move to the right if the random number is 3
case 3:
Move::right(this);
break;
}
}
}