コード例 #1
0
        public void Run()
        {
            _ioService.WriteLine(
                "\t\tOLD MACDONALD HAD A FARM{0}{0}" +
                "Commands:{0}" +
                " - To see the nursery rhyme lyrics, type \"old\".{0}" +
                " - To write new verses with animals of your choosing, type \"new\".{0}" +
                " - To exit the program, type \"exit\".{0}",
                Environment.NewLine);
            try
            {
                while (true)
                {
                    _ioService.Write("Command: ");
                    string command = _ioService.ReadLine();

                    switch (command)
                    {
                    case Commands.Old:
                    {
                        _ioService.WriteLine(GetOldSongLyrics());
                        break;
                    }

                    case Commands.New:
                    {
                        _ioService.WriteLine(MakeNewVerses());
                        break;
                    }

                    case Commands.Exit:
                    {
                        return;
                    }

                    default:
                        break;
                    }
                }
            }
            catch (SongException se)
            {
                _ioService.WriteLine($"Rhyme generation failure: {se.Message}");
            }
            catch (Exception e)
            {
                _ioService.WriteLine(e.Message);
            }
        }