Advertisement
Guest User

Potion Example

a guest
Feb 21st, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.19 KB | None | 0 0
  1. class Program
  2. {
  3.     public struct Potion
  4.     {
  5.         public Potion(string name, float speed, float scale, string sprite)
  6.         {
  7.             m_Name = name;
  8.             m_Speed = speed;
  9.             m_Scale = scale;
  10.             m_Sprite = sprite;
  11.         }
  12.  
  13.         public string m_Name;
  14.         public float m_Speed;
  15.         public float m_Scale;
  16.         public string m_Sprite;
  17.     }
  18.  
  19.  
  20.     public static Dictionary<string, Potion> PotionDictionaryExample = new Dictionary<string, Potion>();
  21.     public static List<Potion> PotionListExample = new List<Potion>();    
  22.  
  23.     static void Main(string[] args)
  24.     {
  25.         ///////////////
  26.         //DICTIONARY
  27.         //If you need to access the potions by name use a dictionary
  28.  
  29.         //setter
  30.         PotionDictionaryExample["Potion 1"] = new Potion("Some name", 5.0f, 1.0f, "image_of_a_potion.tif");
  31.  
  32.         //getter
  33.         Potion potionFromDict = PotionDictionaryExample["Potion 1"];
  34.  
  35.         //print example from your paste
  36.         foreach (var potion in PotionDictionaryExample)
  37.         {
  38.             Console.WriteLine(String.Format("{0} {1} {2} {3} {4}",
  39.                                             potion.Key,
  40.                                             potion.Value.m_Name,
  41.                                             potion.Value.m_Speed,
  42.                                             potion.Value.m_Scale,
  43.                                             potion.Value.m_Sprite));
  44.         }
  45.  
  46.         ///////////////
  47.         //LIST
  48.         //If you just need to access via index eg: Potions[0] use a list
  49.  
  50.         //setter
  51.         PotionListExample.Add(new Potion("Some name", 5.0f, 1.0f, "image_of_a_potion.tif"));
  52.  
  53.         //getter
  54.         Potion potionFromList = PotionListExample[0];
  55.  
  56.         //print example from your paste
  57.         foreach (var potion in PotionListExample)
  58.         {
  59.             Console.WriteLine(String.Format("{0} {1} {2} {3}",
  60.                                             potion.m_Name,
  61.                                             potion.m_Speed,
  62.                                             potion.m_Scale,
  63.                                             potion.m_Sprite));
  64.         }
  65.  
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement