-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclasses.py
More file actions
46 lines (33 loc) · 1.33 KB
/
Copy pathclasses.py
File metadata and controls
46 lines (33 loc) · 1.33 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
"""Solution to Ellen's Alien Game exercise."""
class Alien:
"""Create an Alien object with location x_coordinate and y_coordinate.
Attributes:
(class) total_aliens_created (int): Total number of Alien instances.
x_coordinate (int): Position on the x-axis.
y_coordinate (int): Position on the y-axis.
health (int): Number of health points.
Methods:
hit(): Decrement Alien health by one point.
is_alive(): Return a boolean for if Alien is alive (if health is > 0).
teleport(new_x_coordinate, new_y_coordinate): Move Alien object to new coordinates.
collision_detection(other): Implementation TBD.
"""
total_aliens_created = 0
def __init__(self, x_coordinate, y_coordinate):
self.x_coordinate = x_coordinate
self.y_coordinate = y_coordinate
self.health = 3
Alien.total_aliens_created += 1
def hit(self):
self.health -= 1
def is_alive(self):
return self.health > 0
def teleport(self, x_coordinate, y_coordinate):
self.x_coordinate, self.y_coordinate = x_coordinate, y_coordinate
def collision_detection(self, other):
pass
def new_aliens_collection(positions):
aliens = []
for position in positions:
aliens.append(Alien(position[0], position[1]))
return aliens