public string JoinParty(string[] args) { string faction = args[0]; string characterType = args[1]; string name = args[2]; CharacterFactory characterFactory = new CharacterFactory(); var character = characterFactory.CreateCharacter(faction, characterType, name); characterParty.Add(character); return($"{character.Name} joined the party!"); }
public static void Main() { IReader reader = new Reader(); IWriter writer = new Writer(); IMainController controller = new MainController(); ICharacterFactory characterFactory = new CharacterFactory(); IItemFactory itemFactory = new ItemFactory(); ICommandInterpreter interpreter = new CommandInterpreter (characterFactory, itemFactory, controller); var engine = new Engine(reader, writer, interpreter, controller); engine.Run(); }
// Parameters //• faction – a string //• characterType – string //• name – string //Functionality //Creates a character and adds them to the party. //If the faction is invalid, throw an ArgumentException with the message Invalid faction "{faction}"! //If the character type is invalid, throw an ArgumentException with the message “Invalid character type "{characterType}"!” //Returns the string “{name} joined the party!” public string JoinParty(string[] args) { string factionString = args[0]; string charType = args[1]; string name = args[2]; Faction faction; if (!Enum.TryParse(factionString, out faction)) { throw new ArgumentException($"Invalid faction \"{factionString}\"!"); } Character newCharacter = CharacterFactory.CreateCharacter(factionString, charType, name); this.CharacterParty.Add(newCharacter); return($"{name} joined the party!"); }