-
Notifications
You must be signed in to change notification settings - Fork 2
/
Ellen's Alien Game.py
46 lines (39 loc) · 1.49 KB
/
Ellen's Alien Game.py
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
x_coordinate: int - Position on the x-axis.
y_coordinate: int - Position on the y-axis.
health: int - Amount 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_coordinate1, y_coordinate1):
self.x_coordinate = x_coordinate1
self.y_coordinate = y_coordinate1
Alien.total_aliens_created += 1
self.health = 3
def hit(self):
self.health -= 1
def is_alive(self):
if self.health <= 0:
return False
return True
def teleport(self, new_x_coordinate, new_y_coordinate):
self.x_coordinate = new_x_coordinate
self.y_coordinate = new_y_coordinate
def collision_detection(self, other):
pass
#TODO: create the new_aliens_collection() function below to call your Alien class with a list of coordinates.
def new_aliens_collection(lst_coord):
result_list = []
for coord in lst_coord:
result_list.append(Alien(coord[0], coord[1]))
return result_list