コード例 #1
0
    public void Run()
    {
        string input = reader.ReadLine();

        string[] args     = input.Split();
        string[] elements = args.Skip(1).ToArray();
        var      listy    = factory.Create(elements);


        string command = reader.ReadLine();

        while (command != "END")
        {
            string result = "";

            switch (command)
            {
            case "Move":
                result = listy.Move().ToString();
                break;

            case "HasNext":
                result = listy.HasNext().ToString();
                break;

            case "Print":
                try
                {
                    result = listy.Print();
                }
                catch (InvalidOperationException ioe)
                {
                    result = ioe.Message;
                }
                break;

            case "PrintAll":
                result = string.Join(" ", listy);
                break;
            }

            if (result != "")
            {
                writer.WriteLine(result);
            }


            command = reader.ReadLine();
        }
    }
コード例 #2
0
ファイル: Engine.cs プロジェクト: BiserB/Educational
    public void Run()
    {
        string input = reader.ReadLine();

        string[] args     = input.Split();
        string[] elements = args.Skip(1).ToArray();
        var      listy    = factory.Create(elements);

        try
        {
            string command = reader.ReadLine();

            while (command != "END")
            {
                string result = "";

                switch (command)
                {
                case "Move":
                    result = listy.Move().ToString();
                    writer.WriteLine(result);
                    break;

                case "HasNext":
                    result = listy.HasNext().ToString();
                    writer.WriteLine(result);
                    break;

                case "Print":
                    listy.Print();
                    break;

                default:
                    throw new ArgumentException("Wrong command");
                }

                command = reader.ReadLine();
            }
        }
        catch (ArgumentException ae)
        {
            writer.WriteLine(ae.Message);
        }
        catch (InvalidOperationException ioe)
        {
            writer.WriteLine(ioe.Message);
        }
    }