public void Run() { while (true) { var input = reader.ReadLine().Split(); if (input[0] == "Exit") { Environment.Exit(0); } try { if (input[0] == "AddPlayer") { writer.WriteLine(controller.AddPlayer(input[1])); } else if (input[0] == "AddGun") { writer.WriteLine(controller.AddGun(input[1], input[2])); } else if (input[0] == "AddGunToPlayer") { writer.WriteLine(controller.AddGunToPlayer(input[1])); } else if (input[0] == "Fight") { writer.WriteLine(controller.Fight()); } } catch (Exception ex) { writer.WriteLine(ex.Message); writer.WriteLine(ex.ToString()); } } }
private string ProcessCommand(string[] args) { string command = args[0]; string result = null; switch (command) { case "AddPlayer": result = _controller.AddPlayer(args[1]); break; case "AddGun": result = _controller.AddGun(args[1], args[2]); break; case "AddGunToPlayer": result = _controller.AddGunToPlayer(args[1]); break; case "Fight": result = _controller.Fight(); break; case "Exit": _isRunning = false; Environment.Exit(0); break; } return(result); }
public void Run() { while (true) { string[] input = reader.ReadLine().Split(); if (input[0] == "Exit") { Environment.Exit(0); } try { string result = string.Empty; if (input[0] == "AddGun") { string type = input[1]; string name = input[2]; int bulletsCount = int.Parse(input[3]); result = controller.AddGun(type, name, bulletsCount); } else if (input[0] == "AddPlayer") { string type = input[1]; string username = input[2]; int health = int.Parse(input[3]); int armor = int.Parse(input[4]); string gunName = input[5]; result = controller.AddPlayer(type, username, health, armor, gunName); } else if (input[0] == "StartGame") { result = controller.StartGame(); } else if (input[0] == "Report") { result = controller.Report(); } writer.WriteLine(result); } catch (Exception ex) { writer.WriteLine(ex.Message); //writer.WriteLine(ex.TargetSite.ToString()); //writer.WriteLine(ex.Data.ToString()); //writer.WriteLine(ex.StackTrace); continue; } } }
public void Run() { while (true) { var input = reader.ReadLine().Split(); if (input[0] == "Exit") { Environment.Exit(0); } try { string result = string.Empty; if (input[0] == "AddPlayer") { string username = input[1]; result = controller.AddPlayer(username); } else if (input[0] == "AddGun") { string type = input[1]; string name = input[2]; result = controller.AddGun(type, name); } else if (input[0] == "AddGunToPlayer") { string username = input[1]; result = controller.AddGunToPlayer(username); } else if (input[0] == "Fight") { result = controller.Fight(); } writer.WriteLine(result); } catch (Exception ex) { writer.WriteLine(ex.Message); } } }
public void Run() { while (true) { var input = reader.ReadLine().Split(); if (input[0] == "Exit") { Environment.Exit(0); } try { if (input[0] == "AddPlayer") { string name = input[1]; Console.WriteLine(controller.AddPlayer(name)); } else if (input[0] == "AddGun") { string gunType = input[1]; string gunName = input[2]; Console.WriteLine(controller.AddGun(gunType, gunName)); } else if (input[0] == "AddGunToPlayer") { string name = input[1]; Console.WriteLine(controller.AddGunToPlayer(name)); } else if (input[0] == "Fight") { Console.WriteLine(controller.Fight()); } } catch (Exception ex) { writer.WriteLine(ex.Message); } } }