Skip to content

Commit 6330da1

Browse files
committed
feature: home theatre facade working 🎵
1 parent c19ee03 commit 6330da1

File tree

1 file changed

+46
-9
lines changed

1 file changed

+46
-9
lines changed

chapter07_adapter_facade/separates/separates.py

+46-9
Original file line numberDiff line numberDiff line change
@@ -77,25 +77,22 @@ def play(self, arg):
7777
if isinstance(arg, str):
7878
self.movie = arg
7979
self.current_chapter = 0
80-
print(self.description + " playing \"" + self.movie + "\"")
80+
print(f'{self.description} playing "{self.movie}"')
8181
elif isinstance(arg, int):
8282
if self.movie is None:
8383
print(f"{self.description} can't play chapter {arg} no movie selected")
8484
else:
8585
self.current_chapter = arg
8686
print(
87-
f"{self.description} playing chapter {self.current_chapter}"
88-
+ " of \""
89-
+ self.movie
90-
+ "\""
87+
f'{self.description} playing chapter {self.current_chapter} of "{self.movie}"'
9188
)
9289

9390
def stop(self):
9491
self.current_chapter = 0
95-
print(self.description + " stopped \"" + self.movie + "\"")
92+
print(f'{self.description} stopped "{self.movie}"')
9693

9794
def pause(self):
98-
print(self.description + " paused \"" + self.movie + "\"")
95+
print(f'{self.description} paused "{self.movie}"')
9996

10097
def set_two_channel_audio(self):
10198
print(f"{self.description} set two channel audio")
@@ -104,6 +101,46 @@ def set_surround_audio(self):
104101
print(f"{self.description} set surround audio")
105102

106103

104+
class CdPlayer:
105+
def __init__(self, description, amplifier):
106+
self.description = description
107+
self.current_track = 0
108+
self.amplifier = amplifier
109+
self.title = None
110+
111+
def __str__(self):
112+
return self.description
113+
114+
def on(self):
115+
print(f"{self.description} on")
116+
117+
def off(self):
118+
print(f"{self.description} off")
119+
120+
def play(self, arg):
121+
if isinstance(arg, str):
122+
self.title = arg
123+
self.current_track = 0
124+
print(f'{self.description} playing "{self.movie}"')
125+
elif isinstance(arg, int):
126+
if self.title is None:
127+
print(f"{self.description} can't play track {self.current_track}, no cd inserted")
128+
else:
129+
self.current_track = arg
130+
print(
131+
f'{self.description} playing track {self.current_track}'
132+
)
133+
134+
def eject(self):
135+
print(f'{self.description} eject')
136+
137+
def stop(self):
138+
print(f'{self.description} stopped')
139+
140+
def pause(self):
141+
print(f'{self.description} paused "{self.title}"')
142+
143+
107144
class Projector:
108145
def __init__(self, description, player):
109146
self.description = description
@@ -119,10 +156,10 @@ def off(self):
119156
print(f"{self.description} off")
120157

121158
def wide_screen_mode(self):
122-
print(self.description + " in widescreen mode (16x9 aspect ratio)")
159+
print(f"{self.description} in widescreen mode (16x9 aspect ratio)")
123160

124161
def tv_mode(self):
125-
print(self.description + " in tv mode (4x3 aspect ratio)")
162+
print(f"{self.description} in tv mode (4x3 aspect ratio)")
126163

127164

128165
class Screen:

0 commit comments

Comments
 (0)