Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using MXGP.Core.Contracts;
- using MXGP.IO;
- using MXGP.IO.Contracts;
- using MXGP.Models.Races.Contracts;
- using System;
- using System.Collections.Generic;
- using System.Text;
- namespace MXGP.Core
- {
- public class Engine : IEngine
- {
- private IReader reader;
- private IWriter writer;
- private IChampionshipController controller;
- public Engine()
- {
- this.reader = new ConsoleReader();
- this.writer = new ConsoleWriter();
- this.controller = new ChampionshipController();
- }
- public void Run()
- {
- while (true)
- {
- string[] input = reader.ReadLine().Split();
- string command = input[0];
- string output = "";
- if (command == "End")
- {
- Environment.Exit(0);
- }
- try
- {
- if (command == "CreateRider")
- {
- string riderName = input[1];
- output = controller.CreateRider(riderName);
- }
- else if (command == "CreateMotorcycle")
- {
- string type = input[1];
- string model = input[2];
- int horsePower = int.Parse(input[3]);
- output = controller.CreateMotorcycle(type, model, horsePower);
- }
- else if (command == "AddMotorcycleToRider")
- {
- string riderName = input[1];
- string motoName = input[2];
- output = controller.AddMotorcycleToRider(riderName, motoName);
- }
- else if (command == "AddRiderToRace")
- {
- string raceName = input[1];
- string riderName = input[2];
- output = controller.AddRiderToRace(raceName, riderName);
- }
- else if (command == "CreateRace")
- {
- string name = input[1];
- int laps = int.Parse(input[2]);
- output = controller.CreateRace(name, laps);
- }
- else if (command == "StartRace")
- {
- string name = input[1];
- output = controller.StartRace(name);
- }
- writer.WriteLine(output);
- }
- catch (Exception ex)
- {
- writer.WriteLine(ex.Message);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement