Beispiel #1
0
        public void Run()
        {
            while (true)
            {
                string[] inputArgs = this.reader.ReadLine()
                                     .Split(" ", StringSplitOptions.RemoveEmptyEntries)
                                     .ToArray();

                try
                {
                    if (inputArgs[0] == "End")
                    {
                        break;
                    }
                    else if (inputArgs[0] == "CreateRider")
                    {
                        string name = inputArgs[1];
                        writer.WriteLine(championshipController.CreateRider(name));
                    }
                    else if (inputArgs[0] == "CreateMotorcycle")
                    {
                        string name       = inputArgs[1];
                        string model      = inputArgs[2];
                        int    horsePower = int.Parse(inputArgs[3]);
                        writer.WriteLine(championshipController.CreateMotorcycle(name, model, horsePower));
                    }
                    else if (inputArgs[0] == "AddMotorcycleToRider")
                    {
                        string name            = inputArgs[1];
                        string motorcycleModel = inputArgs[2];
                        writer.WriteLine(championshipController.AddMotorcycleToRider(name, motorcycleModel));
                    }
                    else if (inputArgs[0] == "AddRiderToRace")
                    {
                        string name = inputArgs[1];
                        string race = inputArgs[2];
                        writer.WriteLine(championshipController.AddRiderToRace(name, race));
                    }
                    else if (inputArgs[0] == "CreateRace")
                    {
                        string name = inputArgs[1];
                        int    laps = int.Parse(inputArgs[2]);
                        writer.WriteLine(championshipController.CreateRace(name, laps));
                    }
                    else if (inputArgs[0] == "StartRace")
                    {
                        string name = inputArgs[1];
                        writer.WriteLine(championshipController.StartRace(name));
                    }
                }
                catch (Exception ex)
                {
                    writer.WriteLine(ex.Message);
                }
            }
        }
Beispiel #2
0
        public void Run()
        {
            ;
            while (true)
            {
                var    command     = consoleReader.ReadLine().Split(' ').ToArray();
                string mainCommand = command[0];
                try
                {
                    switch (mainCommand)
                    {
                    case "CreateRider":
                        string name = command[1];
                        Console.WriteLine(controller.CreateRider(name));
                        break;

                    case "CreateMotorcycle":
                        string type  = command[1];
                        string model = command[2];
                        int    hp    = int.Parse(command[3]);
                        Console.WriteLine(controller.CreateMotorcycle(type, model, hp));
                        break;

                    case "AddMotorcycleToRider":
                        string riderName      = command[1];
                        string motorcycleName = command[2];
                        Console.WriteLine(controller.AddMotorcycleToRider(riderName, motorcycleName));
                        break;

                    case "AddRiderToRace":
                        string raceName = command[1];
                        riderName = command[2];
                        Console.WriteLine(controller.AddRiderToRace(raceName, riderName));
                        break;

                    case "CreateRace":
                        name = command[1];
                        int laps = int.Parse(command[2]);
                        Console.WriteLine(controller.CreateRace(name, laps));
                        break;

                    case "StartRace":
                        name = command[1];
                        Console.WriteLine(controller.StartRace(name));
                        break;

                    case "End":
                        return;
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
        }
 public void Run()
 {
     while (true)
     {
         var input = reader.ReadLine().Split();
         if (input[0] == "Exit")
         {
             Environment.Exit(0);
         }
         try
         {
             if (input[0] == "CreateRider")
             {
                 Console.WriteLine(controller.CreateRider(input[1]));
             }
             else if (input[0] == "CreateMotorcycle")
             {
                 Console.WriteLine(controller.CreateMotorcycle(input[1], input[2], int.Parse(input[3])));
             }
             else if (input[0] == "AddMotorcycleToRider")
             {
                 Console.WriteLine(controller.AddMotorcycleToRider(input[1], input[2]));
             }
             else if (input[0] == "AddRiderToRace")
             {
                 Console.WriteLine(controller.AddRiderToRace(input[1], input[2]));
             }
             else if (input[0] == "CreateRace")
             {
                 Console.WriteLine(controller.CreateRace(input[1], int.Parse(input[2])));
             }
             else if (input[0] == "StartRace")
             {
                 Console.WriteLine(controller.StartRace(input[1]));
             }
         }
         catch (Exception ex)
         {
             writer.WriteLine(ex.Message);
         }
     }
 }
Beispiel #4
0
        public void Run()
        {
            while (true)
            {
                string   line  = consoleReader.ReadLine();
                string[] input = line
                                 .Split(" ", StringSplitOptions.RemoveEmptyEntries);

                string command = input[0];

                if (command == "End")
                {
                    break;
                }

                switch (command)
                {
                case "CreateRider":
                {
                    string name = input[1];

                    consoleWriter.WriteLine(controler.CreateRider(name));
                    break;
                }

                case "CreateMotorcycle":
                {
                    string motorcycleType = input[1];
                    string model          = input[2];
                    int    horsePower     = int.Parse(input[3]);

                    consoleWriter.WriteLine(controler.CreateMotorcycle(motorcycleType, model, horsePower));
                    break;
                }

                case "AddMotorcycleToRider":
                {
                    string riderName      = input[1];
                    string motorcycleName = input[2];

                    consoleWriter.WriteLine(controler.AddMotorcycleToRider(riderName, motorcycleName));
                    break;
                }

                case "AddRiderToRace":
                {
                    string raceName  = input[1];
                    string riderName = input[2];

                    consoleWriter.WriteLine(controler.AddRiderToRace(raceName, riderName));
                    break;
                }

                case "CreateRace":
                {
                    string name = input[1];
                    int    laps = int.Parse(input[2]);

                    consoleWriter.WriteLine(controler.CreateRace(name, laps));
                    break;
                }

                case "StartRace":
                {
                    string raceName = input[1];

                    consoleWriter.WriteLine(controler.StartRace(raceName));
                    break;
                }

                default:
                    Console.WriteLine("error");
                    break;
                }
            }
        }
Beispiel #5
0
        public void Run()
        {
            var input   = string.Empty;
            var handler = new ChampionshipController();

            while ((input = Console.ReadLine()) != "End")
            {
                try
                {
                    var args    = input.Split(' ', StringSplitOptions.RemoveEmptyEntries);
                    var command = args[0];
                    switch (command)
                    {
                    case "CreateRider":
                        var name = args[1];
                        Console.WriteLine(handler.CreateRider(name));

                        break;

                    case "CreateMotorcycle":
                        var type  = args[1];
                        var model = args[2];
                        var power = int.Parse(args[3]);
                        Console.WriteLine(handler.CreateMotorcycle(type, model, power));

                        break;

                    case "AddMotorcycleToRider":
                        var ridarName = args[1];
                        var motorName = args[2];
                        Console.WriteLine(handler.AddMotorcycleToRider(ridarName, motorName));

                        break;

                    case "AddRiderToRace":
                        var raceName   = args[1];
                        var ridaarName = args[2];
                        Console.WriteLine(handler.AddRiderToRace(raceName, ridaarName));

                        break;

                    case "CreateRace":
                        var nname = args[1];
                        var laps  = int.Parse(args[2]);
                        Console.WriteLine(handler.CreateRace(nname, laps));
                        break;

                    case "StartRace":
                        var raaaceName = args[1];
                        Console.WriteLine(handler.StartRace(raaaceName));
                        break;
                    }
                }
                catch (InvalidOperationException target)
                {
                    Console.WriteLine(target.Message);
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception.Message);
                }
            }
        }