-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclasses.py
More file actions
65 lines (53 loc) · 1.63 KB
/
classes.py
File metadata and controls
65 lines (53 loc) · 1.63 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
"""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_coordinate, y_coordinate):
"""
1. Create the Alien Class
"""
self.x_coordinate = x_coordinate
self.y_coordinate = y_coordinate
self.health = 3
Alien.total_aliens_created += 1
def hit(self):
"""
2. The `hit` Method
"""
self.health -= 1
def is_alive(self):
"""
3. The `is_alive` Method
"""
return self.health > 0
def teleport(self, x_coordinate, y_coordinate):
"""
The `teleport` Method
"""
self.x_coordinate = x_coordinate
self.y_coordinate = y_coordinate
def collision_detection(self, other_object):
"""
The `collision_detection` Method
"""
pass
# return None
def new_aliens_collection(positions):
"""
to call your Alien class with a list of coordinates.
"""
return [Alien(position[0], position[1]) for position in positions]