Example #1
0
        public string SelectPlaybackComponent(int index)
        {
            var selectionBuilder = new StringBuilder();

            switch (index)
            {
            case 1:
                PlaybackComponent = new AppleHeadset(Output);
                selectionBuilder.AppendLine(Output.WriteLine("Apple Headset playback selected"));
                break;

            case 2:
                PlaybackComponent = new SamsungHeadset(Output);
                selectionBuilder.AppendLine(Output.WriteLine("Samsung Headset playback selected"));
                break;

            case 3:
                PlaybackComponent = new UnofficialAppleHeadset(Output);
                selectionBuilder.AppendLine(Output.WriteLine("Unofficial Apple Headset playback selected"));
                break;

            case 4:
                PlaybackComponent = Speaker;
                Speaker.Output    = Output;
                selectionBuilder.AppendLine(Output.WriteLine("Speaker playback selected"));
                break;

            default:
                selectionBuilder.AppendLine(Output.WriteLine("No playback selected"));
                break;
            }

            if (PlaybackComponent != null)
            {
                selectionBuilder.AppendLine(Output.WriteLine($"Set playback to {nameof(Mobile)}..."));
            }

            return(selectionBuilder.ToString());
        }
        public void IPlayUnitTest()
        {
            FakeOutput output;
            IPlay      device;
            string     expectedMessage;

            ///MonauralSpeaker Test
            output          = new FakeOutput();
            device          = new MonauralSpeakerSystem(new RealSpeaker(2), 20, output);
            expectedMessage = $"{nameof(MonauralSpeakerSystem)} sound";
            IPlayBaseTest(device, expectedMessage, output);

            ///StereoSpeaker Test
            output          = new FakeOutput();
            device          = new StereoSpeakerSystem(new RealSpeaker(2), new RealSpeaker(2), 20, output);
            expectedMessage = $"{nameof(StereoSpeakerSystem)} sound";
            IPlayBaseTest(device, expectedMessage, output);

            ///UnofficialHeadset Test
            output          = new FakeOutput();
            device          = new UnofficialHeadset(new RealSpeaker(2), new RealSpeaker(2), 20, output);
            expectedMessage = $"{nameof(UnofficialHeadset)} sound";
            IPlayBaseTest(device, expectedMessage, output);

            ///SamsungHeadset Test
            output          = new FakeOutput();
            device          = new SamsungHeadset(new RealSpeaker(2), new RealSpeaker(2), 20, output);
            expectedMessage = $"{nameof(SamsungHeadset)} sound";
            IPlayBaseTest(device, expectedMessage, output);

            ///ExternalSpeaker Test
            output          = new FakeOutput();
            device          = new ExternalSpeaker(new RealSpeaker(2), 20, output);
            expectedMessage = $"{nameof(ExternalSpeaker)} sound";
            IPlayBaseTest(device, expectedMessage, output);
        }
Example #3
0
        private void SetPlaybackComponentToMobile(WinFormOuput winformOutput)
        {
            IPlayback playbackComponent = null;

            if (radioButton1.Checked)
            {
                playbackComponent = new iPhoneHeadset(winformOutput);
            }
            else if (radioButton2.Checked)
            {
                playbackComponent = new SamsungHeadset(winformOutput);
            }
            else if (radioButton3.Checked)
            {
                playbackComponent = new UnofficialiPhoneHeadset(winformOutput);
            }
            else if (radioButton4.Checked)
            {
                playbackComponent = new PhoneSpeaker(winformOutput);
            }
            mobile.PlaybackComponent = playbackComponent;
            winformOutput.WriteLine("Set playback to Mobile...");
            mobile.Play();
        }
Example #4
0
        static void Main(string[] args)
        {
            IOutput   output    = new ConsoleOutput();
            IPlayback playback  = new HtcHeadset();
            IUsb      usbDevice = new Charger();

            StringBuilder toConsole = new StringBuilder();

            toConsole.AppendLine("Please select payback device (index expected):");
            toConsole.AppendLine("1 - HtcHeadset");
            toConsole.AppendLine("2 - SamsungHeadset");
            toConsole.AppendLine("3 - XiaomiHeadset");

            Console.WriteLine(toConsole.ToString());

            ConsoleKeyInfo userInput = Console.ReadKey();

            Console.WriteLine();

            switch (userInput.KeyChar)
            {
            case ('1'):
                playback = new HtcHeadset(output);
                break;

            case ('2'):
                playback = new SamsungHeadset(output);
                break;

            case ('3'):
                playback = new XiaomiHeadset(output);
                break;

            default:
                Console.WriteLine("You have entered invalid information. HtcHeadset is selected for you");
                break;
            }

            toConsole = new StringBuilder();
            toConsole.AppendLine("Please select usb device to use (index expected):");
            toConsole.AppendLine("1 - Charger");
            toConsole.AppendLine("2 - Dynamics");
            toConsole.AppendLine("3 - GameConsole");

            Console.WriteLine(toConsole.ToString());

            userInput = Console.ReadKey();
            Console.WriteLine();

            switch (userInput.KeyChar)
            {
            case ('1'):
                usbDevice = new Charger();
                break;

            case ('2'):
                usbDevice = new Dynamics();
                break;

            case ('3'):
                usbDevice = new GameConsole();
                break;

            default:
                Console.WriteLine("You have entered invalid information so you will just charge the mobile");
                break;
            }

            Mobile mobile = new Mobile(playback, usbDevice);

            mobile.Play(new object());
            mobile.UsbDevice.Use(new object());

            Console.ReadKey();
        }
        private void ApplyButton_Click(object sender, EventArgs e)
        {
            _clickNum++;
            switch (_clickNum)
            {
            case 1:
                IPlayback playback;
                if (Option1.Checked)
                {
                    playback = new MeizuHeadset(output);
                }
                else if (Option2.Checked)
                {
                    playback = new SamsungHeadset(output);
                }
                else if (Option3.Checked)
                {
                    playback = new UnofficialiPhoneHeadset(output);
                }
                else if (Option4.Checked)
                {
                    playback = new PortableSpeaker(output);
                }
                else
                {
                    throw new ArgumentOutOfRangeException();
                }
                phone.PlaybackComponent = playback;
                output.WriteLine($"{playback.GetType().Name} playback selected");
                output.WriteLine("Set playback to Mobile...");
                output.WriteLine("Play sound in Mobile:");
                phone.Play("Song");
                FormTopLabel    = "Select charger component (specify index):";
                FormOption1     = "1 - SamsungCharger";
                FormOption2     = "2 - MeizuCharger";
                FormOption3     = "3 - OfficialiPhoneCharger";
                FormOption4     = "";
                Option1.Checked = true;
                break;

            case 2:
                output.WriteLine("");
                ICharger charger;
                if (Option1.Checked)
                {
                    charger = new SamsungCharger(output);
                }
                else if (Option2.Checked)
                {
                    charger = new MeizuCharger(output);
                }
                else if (Option3.Checked)
                {
                    charger = new OfficialiPhoneCharger(output);
                }
                else
                {
                    throw new ArgumentOutOfRangeException();
                }
                phone.ChargerComponent = charger;
                output.WriteLine($"{charger.GetType().Name} selected");
                output.WriteLine("Plug in charger to Mobile:");
                phone.InnerCharge(null);
                FormTopLabel    = "Select protector component (specify index):";
                FormOption1     = "1 - LeatherProtector";
                FormOption2     = "2 - SteelProtector";
                FormOption3     = "";
                FormOption4     = "";
                Option1.Checked = true;
                break;

            case 3:
                output.WriteLine("");
                IProtector protector;
                if (Option1.Checked)
                {
                    protector = new LeatherProtector(output);
                }
                else if (Option2.Checked)
                {
                    protector = new SteelProtector(output);
                }
                else
                {
                    throw new ArgumentOutOfRangeException();
                }
                phone.ProtectorComponent = protector;
                output.WriteLine($"{protector.GetType().Name} selected");
                output.WriteLine("Put protector on Mobile:");
                phone.Put(protector);
                break;
            }
        }
Example #6
0
        static void Main(string[] args)
        {
            IOutput output = new ConsoleOutput();

            MobilePhone phone;

            phone = new SimCorpMobile();
            output.WriteLine(phone.GetDescription());

            output.WriteLine("");
            output.WriteLine("Select playback component (specify index):");
            output.WriteLine("1 - MeizuHeadset");
            output.WriteLine("2 - SamsungHeadset");
            output.WriteLine("3 - UnofficialiPhoneHeadset");
            output.WriteLine("4 - PortableSpeaker");

            int  value;
            bool isBadInput;

            do
            {
                isBadInput = !int.TryParse(Console.ReadLine(), out value);
                if (isBadInput || value > 4 || value < 1)
                {
                    output.WriteLine("Wrong value, please try again: ");
                    isBadInput = true;
                }
            } while (isBadInput);

            IPlayback playback;

            switch (value)
            {
            case 1:
                playback = new MeizuHeadset(output);
                break;

            case 2:
                playback = new SamsungHeadset(output);
                break;

            case 3:
                playback = new UnofficialiPhoneHeadset(output);
                break;

            case 4:
                playback = new PortableSpeaker(output);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            phone.PlaybackComponent = playback;
            output.WriteLine($"{playback.GetType().Name} playback selected");
            output.WriteLine("Set playback to Mobile...");
            output.WriteLine("Play sound in Mobile:");
            phone.Play("Song");

            //next

            output.WriteLine("");
            output.WriteLine("Select charger component (specify index):");
            output.WriteLine("1 - SamsungCharger");
            output.WriteLine("2 - MeizuCharger");
            output.WriteLine("3 - OfficialiPhoneCharger");

            do
            {
                isBadInput = !int.TryParse(Console.ReadLine(), out value);
                if (isBadInput || value > 3 || value < 1)
                {
                    output.WriteLine("Wrong value, please try again: ");
                    isBadInput = true;
                }
            } while (isBadInput);

            ICharger charger;

            switch (value)
            {
            case 1:
                charger = new SamsungCharger(output);
                break;

            case 2:
                charger = new MeizuCharger(output);
                break;

            case 3:
                charger = new OfficialiPhoneCharger(output);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            phone.ChargerComponent = charger;
            output.WriteLine($"{charger.GetType().Name} selected");
            output.WriteLine("Plug in charger to Mobile:");
            phone.Charge(null);

            //next

            output.WriteLine("");
            output.WriteLine("Select protector component (specify index):");
            output.WriteLine("1 - LeatherProtector");
            output.WriteLine("2 - SteelProtector");

            do
            {
                isBadInput = !int.TryParse(Console.ReadLine(), out value);
                if (isBadInput || value > 2 || value < 1)
                {
                    output.WriteLine("Wrong value, please try again: ");
                    isBadInput = true;
                }
            } while (isBadInput);

            IProtector protector;

            switch (value)
            {
            case 1:
                protector = new LeatherProtector(output);
                break;

            case 2:
                protector = new SteelProtector(output);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            phone.ProtectorComponent = protector;
            output.WriteLine($"{protector.GetType().Name} selected");
            output.WriteLine("Put protector on Mobile:");
            phone.Put(protector);

            Console.ReadLine();
        }