-
Notifications
You must be signed in to change notification settings - Fork 0
/
pirates.py
57 lines (50 loc) · 1.83 KB
/
pirates.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
47
48
49
50
51
52
53
54
55
56
57
import random
class Pirate:
def __init__(self):
self.state = "alive"
self.intoxication = 0
def drink_some_rum(self):
"""
intoxicates the Pirate by one
"""
if self.state == "dead":
print("He's dead.")
else:
self.intoxication += 1
return self.intoxication
def hows_it_going_mate(self):
"""
When called, the Pirate replies:
- if drinkSomeRum was called less than 4 times: "Pour me anudder!"
- else: "Arghh, I'ma Pirate. How d'ya d'ink its goin?" Then the pirate passes out and sleeps it off (gets rid
of intoxication).
"""
if self.state == "dead":
print("He's dead.")
elif self.intoxication < 4:
print("Pour me anudder!")
else:
print("Arghh, I'ma Pirate. How d'ya d'ink its goin?")
self.intoxication = 0
return self.intoxication
def brawl(self, second_pirate):
"""
Pirate fights another pirate (if both of them are alive):
- there is 1/3 chance that this dies, the other dies or they both pass out. - die()
"""
if self.state and second_pirate.state == "alive":
possible_states = ["This pirate dies.", "The second pirate dies.", "Both pirates passed out."]
result = random.choice(possible_states)
print(result)
else:
print("He's dead.")
if result == possible_states[0]:
return self.die()
elif result == possible_states[1]:
return second_pirate.die()
else:
return self.die(), second_pirate.die()
def die(self):
"""This kills off the pirate. When a pirate is dead, every method simply results in 'he's dead'."""
self.state = "dead"
return self.state