Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 17th, 2012  |  syntax: None  |  size: 1.74 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. ================================
  2. Monster Class:
  3. ================================
  4.  
  5. public class Monster
  6.     {
  7.         List<string> statusEffects;
  8.  
  9.         public Monster()
  10.         {
  11.             statusEffects = new List<string>();
  12.         }
  13.  
  14.         public bool HasStatusEffect(string statusEffectName)
  15.         {
  16.         }
  17.  
  18.         public bool AddStatusEffect(string statusEffectName)
  19.         {
  20.         }
  21.  
  22.         public bool RemoveStatusEffect(string statusEffectName)
  23.         {
  24.         }
  25.     }
  26.  
  27. ================================
  28. Python Script:
  29. ================================
  30.  
  31. import sys
  32.  
  33. def Poison(monster):
  34.         if monster.HasStatusEffect("poison"):
  35.                 print 'Monster already poisoned!'
  36.         else:
  37.                 monster.AddStatusEffect("poison")
  38.                 print 'Monster poisoned!'
  39.  
  40. def Unpoison(monster):
  41.         if monster.RemoveStatusEffect("poison"): # returns true if successful
  42.                 print 'Monster unpoisoned!'
  43.         else:
  44.                 print 'Monster is not currently poisoned!'
  45.  
  46. ================================
  47. C# Code:
  48. ================================
  49.  
  50. static void Main(string[] args)
  51.         {
  52.             // Instantiate new monster
  53.             Monster myMonster = new Monster();
  54.  
  55.             // Host a new python runtime
  56.             var pythonRuntime = Python.CreateRuntime();
  57.  
  58.             // Create our execution object and run the defined methods
  59.             dynamic test = pythonRuntime.UseFile(@"C:\Test.py");
  60.             test.Poison(myMonster);
  61.             test.Poison(myMonster);
  62.             test.Unpoison(myMonster);
  63.             test.Unpoison(myMonster);
  64.         }
  65.  
  66. ================================
  67. Returns:
  68. ================================
  69.  
  70. Monster poisoned!
  71. Monster already poisoned!
  72. Monster unpoisoned!
  73. Monster is not currently poisoned!