Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.88 KB | None | 0 0
  1. // IAttackAction.cs
  2.  
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7.  
  8. namespace interface_demo
  9. {
  10.     interface IAttackAction
  11.     {
  12.         void attack();
  13.     }
  14. }
  15.  
  16.  
  17. // ===============================================
  18.  
  19.  
  20. // Archer.cs
  21.  
  22. using System;
  23. using System.Collections.Generic;
  24. using System.Linq;
  25. using System.Text;
  26.  
  27. namespace interface_demo
  28. {
  29.     class Archer: IAttackAction
  30.     {
  31.         public void attack()
  32.         {
  33.             Console.Out.WriteLine("Archer: shoots arrows.");  
  34.         }
  35.     }
  36. }
  37.  
  38.  
  39. // =========================================
  40.  
  41. // Rifleman.cs
  42.  
  43. using System;
  44. using System.Collections.Generic;
  45. using System.Linq;
  46. using System.Text;
  47.  
  48. namespace interface_demo
  49. {
  50.     class Rifleman: IAttackAction
  51.     {
  52.         public void attack()
  53.         {
  54.             Console.Out.WriteLine("Rifleman: starts shooting.");  
  55.         }
  56.     }
  57. }
  58.  
  59.  
  60. // ==================================
  61.  
  62. // Swordsman.cs
  63.  
  64. using System;
  65. using System.Collections.Generic;
  66. using System.Linq;
  67. using System.Text;
  68.  
  69. namespace interface_demo
  70. {
  71.     class Swordsman: IAttackAction
  72.     {
  73.         public void attack()
  74.         {
  75.             Console.Out.WriteLine("Swordsman: swings battlesword.");  
  76.         }
  77.     }
  78. }
  79.  
  80.  
  81. // ================================
  82.  
  83.  
  84. // Main.cs
  85.  
  86.  
  87. using System;
  88. using System.Collections.Generic;
  89. using System.Linq;
  90. using System.Text;
  91.  
  92. namespace interface_demo
  93. {
  94.     class Program
  95.     {
  96.         public static void Controller(IAttackAction Unit)
  97.         {
  98.             Unit.attack();
  99.         }
  100.  
  101.         static void Main(string[] args)
  102.         {
  103.             Controller(new Archer());
  104.             Controller(new Swordsman());
  105.             Controller(new Rifleman());
  106.             Console.Out.WriteLine("Press any key to quit...");  
  107.             Console.ReadKey(false);  
  108.         }
  109.     }
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement