mirror of
https://codeberg.org/andyscott/exercism.git
synced 2024-11-09 13:20:48 -05:00
44 lines
717 B
C++
44 lines
717 B
C++
namespace targets {
|
|
class Alien {
|
|
public:
|
|
Alien(int x, int y) {
|
|
x_coordinate = x;
|
|
y_coordinate = y;
|
|
health = 3;
|
|
}
|
|
|
|
int get_health() { return health; }
|
|
|
|
bool hit() {
|
|
if (health > 0) {
|
|
health -= 1;
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
bool is_alive() { return health > 0; }
|
|
|
|
bool teleport(int x_new, int y_new) {
|
|
x_coordinate = x_new;
|
|
y_coordinate = y_new;
|
|
return true;
|
|
}
|
|
|
|
bool collision_detection(Alien other_alien) {
|
|
if (x_coordinate == other_alien.x_coordinate &&
|
|
y_coordinate == other_alien.y_coordinate) {
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
int x_coordinate, y_coordinate;
|
|
|
|
private:
|
|
int health;
|
|
};
|
|
|
|
} // namespace targets
|