public void ProcessCommand(string input) { if (string.IsNullOrEmpty(input)) { IsRunning = false; return; } string[] args = input.Split(); string command = args[0]; args = args.Skip(1).ToArray(); switch (command) { case "JoinParty": writer.WriteLine(dungeonMaster.JoinParty(args)); break; case "AddItemToPool": writer.WriteLine(dungeonMaster.AddItemToPool(args)); break; case "PickUpItem": writer.WriteLine(dungeonMaster.PickUpItem(args)); break; case "UseItem": writer.WriteLine(dungeonMaster.UseItem(args)); break; case "UseItemOn": writer.WriteLine(dungeonMaster.UseItemOn(args)); break; case "GiveCharacterItem": writer.WriteLine(dungeonMaster.GiveCharacterItem(args)); break; case "GetStats": writer.WriteLine(dungeonMaster.GetStats()); break; case "Attack": writer.WriteLine(dungeonMaster.Attack(args)); break; case "Heal": writer.WriteLine(dungeonMaster.Heal(args)); break; case "EndTurn": writer.WriteLine(dungeonMaster.EndTurn()); break; case "IsGameOver": writer.WriteLine(dungeonMaster.IsGameOver().ToString()); break; } }
private string ReadAndExecuteCommand(string[] tokens, string command, string result) { switch (command) { case "JoinParty": result = dungeonMaster.JoinParty(tokens); break; case "AddItemToPool": result = dungeonMaster.AddItemToPool(tokens); break; case "PickUpItem": result = dungeonMaster.PickUpItem(tokens); break; case "UseItem": result = dungeonMaster.UseItem(tokens); break; case "UseItemOn": result = dungeonMaster.UseItemOn(tokens); break; case "GiveCharacterItem": result = dungeonMaster.GiveCharacterItem(tokens); break; case "GetStats": result = dungeonMaster.GetStats(); break; case "Attack": result = dungeonMaster.Attack(tokens); break; case "Heal": result = dungeonMaster.Heal(tokens); break; case "EndTurn": result = dungeonMaster.EndTurn(tokens); break; } return(result); }
public void Run() { var operations = new List <string>(); string input = Console.ReadLine(); while (true) { if (string.IsNullOrEmpty(input)) { break; } operations.Add(input); input = Console.ReadLine(); } var isItOver = true; foreach (var operation in operations) { if (dm.IsGameOver()) { Console.WriteLine(OutputMessage.FinalStats); Console.WriteLine(dm.GetStats()); isItOver = false; break; } var inputArgs = operation.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries).ToArray(); var command = inputArgs[0]; var args = inputArgs.Skip(1).ToArray(); try { switch (command) { case "JoinParty": Console.WriteLine(dm.JoinParty(args)); break; case "AddItemToPool": Console.WriteLine(dm.AddItemToPool(args)); break; case "PickUpItem": Console.WriteLine(dm.PickUpItem(args)); break; case "UseItem": Console.WriteLine(dm.UseItem(args)); break; case "UseItemOn": Console.WriteLine(dm.UseItemOn(args)); break; case "GiveCharacterItem": Console.WriteLine(dm.GiveCharacterItem(args)); break; case "GetStats": Console.WriteLine(dm.GetStats()); break; case "Attack": Console.WriteLine(dm.Attack(args)); break; case "Heal": Console.WriteLine(dm.Heal(args)); break; case "EndTurn": Console.WriteLine(dm.EndTurn(args)); break; default: throw new InvalidOperationException("Wrong command!"); } } catch (ArgumentException ex) { Console.WriteLine("Parameter Error: " + ex.Message); } catch (InvalidOperationException ex) { Console.WriteLine("Invalid Operation: " + ex.Message); } } if (isItOver) { Console.WriteLine(OutputMessage.FinalStats); Console.WriteLine(dm.GetStats()); } }
private void ExecuteCommand(string input) { string[] commandArg = input.Split(" "); string command = commandArg[0]; commandArg = commandArg.Skip(1).ToArray(); try { switch (command) { case "JoinParty": Console.WriteLine(dungeonMaster.JoinParty(commandArg)); break; case "AddItemToPool": Console.WriteLine(dungeonMaster.AddItemToPool(commandArg)); break; case "PickUpItem": Console.WriteLine(dungeonMaster.PickUpItem(commandArg)); break; case "UseItem": Console.WriteLine(dungeonMaster.UseItem(commandArg)); break; case "UseItemOn": Console.WriteLine(dungeonMaster.UseItemOn(commandArg)); break; case "GiveCharacterItem": Console.WriteLine(dungeonMaster.GiveCharacterItem(commandArg)); break; case "GetStats": Console.WriteLine(dungeonMaster.GetStats()); break; case "Attack": Console.WriteLine(dungeonMaster.Attack(commandArg)); break; case "Heal": Console.WriteLine(dungeonMaster.Heal(commandArg)); break; case "EndTurn": Console.WriteLine(dungeonMaster.EndTurn(commandArg)); break; } } catch (ArgumentException e) { Console.WriteLine($"Parameter Error: {e.Message}"); } catch (InvalidOperationException e) { Console.WriteLine($"Invalid Operation: {e.Message}"); } }
static void Main(string[] args) { var master = new DungeonMaster(); while (true) { var input = Console.ReadLine(); if (String.IsNullOrEmpty(input)) { var builder = new StringBuilder(); builder.AppendLine("Final stats:"); builder.Append(master.GetStats()); Console.WriteLine(builder.ToString().Trim()); return; } string[] command = input.Split(); var arguments = command.Skip(1).ToArray(); try { switch (command[0]) { case "JoinParty": Console.WriteLine(master.JoinParty(arguments)); break; case "AddItemToPool": Console.WriteLine(master.AddItemToPool(arguments)); break; case "PickUpItem": Console.WriteLine(master.PickUpItem(arguments)); break; case "UseItem": Console.WriteLine(master.UseItem(arguments)); break; case "UseItemOn": Console.WriteLine(master.UseItemOn(arguments)); break; case "GiveCharacterItem": Console.WriteLine(master.GiveCharacterItem(arguments)); break; case "GetStats": Console.WriteLine(master.GetStats()); break; case "Attack": Console.WriteLine(master.Attack(arguments)); break; case "Heal": Console.WriteLine(master.Heal(arguments)); break; case "EndTurn": Console.WriteLine(master.EndTurn(arguments)); if (master.IsGameOver()) { var builder = new StringBuilder(); builder.AppendLine("Final stats:"); builder.Append((master.GetStats())); Console.WriteLine(builder.ToString().Trim()); return; } break; case "IsGameOver": Console.WriteLine(master.IsGameOver()); break; } } catch (ArgumentException ae) { Console.WriteLine($"Parameter Error: {ae.Message}"); } catch (InvalidOperationException ioe) { Console.WriteLine($"Invalid Operation: {ioe.Message}"); } } }
public void Run() { while (!dungeonMaster.IsGameOver()) { string input = Console.ReadLine(); if (string.IsNullOrEmpty(input)) { break; } string[] tokens = input.Split(); string command = tokens[0]; tokens = tokens.Skip(1).ToArray(); try { switch (command) { case "JoinParty": sb.AppendLine(dungeonMaster.JoinParty(tokens)); break; case "AddItemToPool": sb.AppendLine(dungeonMaster.AddItemToPool(tokens)); break; case "PickUpItem": sb.AppendLine(dungeonMaster.PickUpItem(tokens)); break; case "UseItem": sb.AppendLine(dungeonMaster.UseItem(tokens)); break; case "UseItemOn": sb.AppendLine(dungeonMaster.UseItemOn(tokens)); break; case "GiveCharacterItem": sb.AppendLine(dungeonMaster.GiveCharacterItem(tokens)); break; case "GetStats": sb.AppendLine(dungeonMaster.GetStats()); break; case "Attack": sb.AppendLine(dungeonMaster.Attack(tokens)); break; case "Heal": sb.AppendLine(dungeonMaster.Heal(tokens)); break; case "EndTurn": sb.AppendLine(dungeonMaster.EndTurn(tokens)); break; default: break; } } catch (ArgumentException ae) { sb.AppendLine($"Parameter Error: {ae.Message}"); } catch (InvalidOperationException ioe) { sb.AppendLine($"Invalid Operation: {ioe.Message}"); } } sb.AppendLine("Final stats:") .AppendLine(dungeonMaster.GetStats()); Console.WriteLine(sb.ToString().Trim()); }