Advertisement
ralichka

Engine-07.12.2019

Apr 11th, 2020
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.79 KB | None | 0 0
  1. using MXGP.Core.Contracts;
  2. using MXGP.IO;
  3. using MXGP.IO.Contracts;
  4. using MXGP.Models.Races.Contracts;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Text;
  8.  
  9. namespace MXGP.Core
  10. {
  11.     public class Engine : IEngine
  12.     {
  13.         private IReader reader;
  14.         private IWriter writer;
  15.         private IChampionshipController controller;
  16.         public Engine()
  17.         {
  18.             this.reader = new ConsoleReader();
  19.             this.writer = new ConsoleWriter();
  20.             this.controller = new ChampionshipController();
  21.         }
  22.  
  23.         public void Run()
  24.         {
  25.             while (true)
  26.             {
  27.                 string[] input = reader.ReadLine().Split();
  28.                 string command = input[0];
  29.  
  30.                 string output = "";
  31.  
  32.                 if (command == "End")
  33.                 {
  34.                     Environment.Exit(0);
  35.                 }
  36.  
  37.                 try
  38.                 {
  39.                     if (command == "CreateRider")
  40.                     {
  41.                         string riderName = input[1];
  42.                         output = controller.CreateRider(riderName);
  43.                     }
  44.                     else if (command == "CreateMotorcycle")
  45.                     {
  46.                         string type = input[1];
  47.                         string model = input[2];
  48.                         int horsePower = int.Parse(input[3]);
  49.  
  50.                         output = controller.CreateMotorcycle(type, model, horsePower);
  51.                     }
  52.                     else if (command == "AddMotorcycleToRider")
  53.                     {
  54.                         string riderName = input[1];
  55.                         string motoName = input[2];
  56.  
  57.                         output = controller.AddMotorcycleToRider(riderName, motoName);
  58.                     }
  59.                     else if (command == "AddRiderToRace")
  60.                     {
  61.                         string raceName = input[1];
  62.                         string riderName = input[2];
  63.  
  64.                         output = controller.AddRiderToRace(raceName, riderName);
  65.                     }
  66.                     else if (command == "CreateRace")
  67.                     {
  68.                         string name = input[1];
  69.                         int laps = int.Parse(input[2]);
  70.  
  71.                         output = controller.CreateRace(name, laps);
  72.                     }
  73.                     else if (command == "StartRace")
  74.                     {
  75.                         string name = input[1];
  76.  
  77.                         output = controller.StartRace(name);
  78.                     }
  79.  
  80.                     writer.WriteLine(output);
  81.                 }
  82.                 catch (Exception ex)
  83.                 {
  84.  
  85.                     writer.WriteLine(ex.Message);
  86.                 }
  87.             }
  88.         }
  89.     }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement