This repository has been archived on 2022-11-20. You can view files and clone it, but cannot push or open issues or pull requests.
patterns/facade/hometheater/cdplayer.d

72 lines
1.3 KiB
D
Raw Normal View History

2022-11-16 13:43:46 +00:00
module cdplayer;
import amplifier;
import std.stdio : writeln;
import std.conv : to;
class CdPlayer
{
private string description;
private int currentTrack;
private Amplifier amplifier;
private string title;
this(string description, Amplifier amplifier)
{
this.description = description;
this.amplifier = amplifier;
}
void on()
{
writeln(description ~ " on");
}
void off()
{
writeln(description ~ " off");
}
void eject()
{
title = null;
writeln(description ~ " eject");
}
void play(string title)
{
this.title = title;
currentTrack = 0;
writeln(description ~ " playing \"" ~ title ~ "\"");
}
void play(int track)
{
if (title is null)
{
writeln(description ~ " can't play track " ~ currentTrack.to!string ~ " no cd inserted");
}
else
{
currentTrack = track;
writeln(description ~ " playing track " ~ currentTrack.to!string);
}
}
void stop()
{
currentTrack = 0;
writeln(description ~ " stopped");
}
void pause()
{
writeln(description ~ " paused \"" ~ title ~ "\"");
}
override string toString() const
{
return description;
}
}