public Engine(IReader reader, IWriter writer) { this.reader = reader; this.writer = writer; privateFactory = new PrivateFactory(); generalFactory = new GeneralFacatory(); engineerFactory = new EngineerFactory(); commandoFactory = new CommandoFactory(); spyFactory = new SpyFactory(); }
public Engine() { this.army = new List <ISoldier>(); this.commandoFactory = new CommandoFactory(); this.engineerFactory = new EngineerFactory(); this.lieutenantGeneralFactory = new LieutenantGeneralFactory(); this.missionFactory = new MissionFactory(); this.privateFactory = new PrivateFactory(); this.repairFactory = new RepairFactory(); this.spyFactory = new SpyFactory(); }
private static void Execute(string command) { var arr = command.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var type = arr[0]; Soldier currentSoldier; arr = arr.Skip(1).ToArray(); switch (type) { case "Private": currentSoldier = PrivateFactory.CreatePrivate(arr); break; case "LieutenantGeneral": currentSoldier = LieutenantGeneralFactory.CreateLieutenantGeneral(arr, soldiers); break; case "Engineer": try { currentSoldier = EngineerFactory.CreateEmgeneer(arr); } catch (ArgumentException) { return; } break; case "Commando": currentSoldier = CommandoFactory.CreateCommando(arr); break; case "Spy": currentSoldier = SpyFactory.CreateSpy(arr); break; default: throw new ArgumentException(); } soldiers.Add(currentSoldier); }
public void Run() { string input; while ((input = reader.ReadLine()) != STOP_WHILE) { string[] arg = input.Split(" ", StringSplitOptions.RemoveEmptyEntries).ToArray(); string type = arg[0]; arg = arg.Skip(1).ToArray(); try { switch (type) { case PRIVATE: soldiers.Add(PrivateFactory.CreatePrivate(arg)); break; case LEUTENANT: soldiers.Add(LeutenantGeneralFactory.CreateLeutenantGeneral(arg, this.soldiers)); break; case ENGINEER: soldiers.Add(EngineerFactory.CreateEngineer(arg)); break; case COMMANDO: soldiers.Add(CommandoFactory.CreateCommando(arg)); break; case SPY: soldiers.Add(SpyFactory.CreateSpy(arg)); break; } } catch (Exception) { continue; } } this.soldiers.ToList().ForEach(x => writer.WriteLine(x.ToString())); }