Advertisement
Guest User

Untitled

a guest
Aug 21st, 2022
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.39 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3.  
  4.  
  5. public enum ItemType
  6. {
  7. NONE = 0,
  8.  
  9. GOD_HAMMER_ELITE = 1000,
  10. DEAVIL_HAMMER = 1001,
  11.  
  12. SPEAR_OF_FIRE         = 2000,
  13.  
  14. ARMOR_OF_ANGEL_DEFENCE = 3000,
  15. GOOD_BUCKLER           = 3001,
  16.  
  17. NECKLACE_OF_FROST = 4000
  18. }
  19.  
  20. public enum WeaponType
  21. {
  22.     NONE = 0,
  23.    
  24.     ARMOR = 1,
  25.     SPEAR = 2,
  26.     HAMMER = 3,
  27.     JEWELERY = 4
  28. }
  29.  
  30.  
  31. public static class ItemHelper
  32. {
  33.     public static IEnumerable getAllValues()
  34.     {
  35.         return Enum.GetValues(typeof(ItemType));
  36.     }
  37.  
  38.     public static bool IsWeapon(Item itemType, out Weapon weapon)
  39.     {
  40.         if(itemType is Weapon currentWeapon)
  41.         {
  42.             weapon = currentWeapon;
  43.             return true;
  44.         }
  45.  
  46.         weapon = null;
  47.         return false;
  48.     }
  49. }
  50.  
  51. public class Item
  52. {
  53.     protected ItemType itemType;
  54.    
  55.     protected Item(ItemType type)
  56.     {
  57.         itemType = type;
  58.     }
  59.  
  60.     public string GetDescription()
  61.     {
  62.         return ItemDescription.GetDescription(itemType);
  63.     }
  64. }
  65.  
  66. public class Weapon : Item
  67. {
  68.     public Weapon(ItemType type) : base (type)
  69.     {
  70.         itemType = type;
  71.     }
  72.    
  73.     public WeaponType GetType()
  74.     {
  75.         switch (itemType)
  76.         {
  77.             case ItemType.GOD_HAMMER_ELITE:
  78.             case ItemType.DEAVIL_HAMMER:
  79.                 return WeaponType.HAMMER;
  80.            
  81.             case ItemType.SPEAR_OF_FIRE:
  82.                 return WeaponType.SPEAR;
  83.            
  84.             case ItemType.ARMOR_OF_ANGEL_DEFENCE:
  85.             case ItemType.GOOD_BUCKLER:
  86.                 return WeaponType.ARMOR;
  87.            
  88.             default:
  89.                 return WeaponType.NONE;
  90.         }
  91.     }
  92. }
  93.  
  94. public static class ItemDescription
  95. {
  96.     private const string GOD_HAMMER_ELITE_DESC = "Hand tool consisting of a solid head set crosswise on a handle and used for pounding";
  97.     private const string SPEAR_OF_FIRE_DESC    = "Weapon with a pointed tip, typically of steel, and a long shaft, used for thrusting or throwing.";
  98.  
  99.     public static string GetDescription(ItemType itemType)
  100.     {
  101.         switch (itemType)
  102.         {
  103.             case ItemType.GOD_HAMMER_ELITE: return GOD_HAMMER_ELITE_DESC;
  104.             case ItemType.SPEAR_OF_FIRE:    return SPEAR_OF_FIRE_DESC;
  105.  
  106.             default:
  107.                 throw new ArgumentOutOfRangeException(nameof(itemType), itemType, null);
  108.         }
  109.     }
  110. }
  111.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement