Advertisement
Danny_Berova

ExamCharacterFactory

Mar 20th, 2018
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.98 KB | None | 0 0
  1. using DungeonsAndCodeWizards.Models;
  2. using DungeonsAndCodeWizards.Models.Characters;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Text;
  6.  
  7. namespace DungeonsAndCodeWizards.Factories
  8. {
  9.    public class CharacterFactory
  10.     {
  11.         public Character CreateCharacter(string factionInput, string givenType, string name)
  12.         {
  13.             if (factionInput != "CSharp" && factionInput != "Java")
  14.             {
  15.                 throw new ArgumentException($"Invalid faction \"{factionInput}\"!");
  16.             }
  17.  
  18.             Faction faction = (Faction)Enum.Parse(typeof(Faction), factionInput);
  19.  
  20.             switch (givenType)
  21.             {
  22.                 case "Warrior":
  23.                     return new Warrior(name, faction);
  24.                 case "Cleric":
  25.                     return new Cleric(name, faction);
  26.                 default:
  27.                     throw new ArgumentException($"Invalid character type \"{givenType}\"!");
  28.             }
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement