Advertisement
Guest User

Untitled

a guest
Sep 27th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.66 KB | None | 0 0
  1. public static class Mediator
  2. {
  3.  
  4.     public void Run()
  5.     {
  6.         Brain humman = new Brain();
  7.     }
  8.  
  9. }
  10.  
  11.  
  12. class Brain
  13. {
  14.     public Brain()
  15.     {
  16.         CreateBodyPrts();
  17.     }
  18.  
  19. public static void CreateBodyPrts()
  20. {
  21.      Ear = new Ear(this);
  22.      Hand = new Hand(this);
  23.      Eye = new Eye(this);
  24. }
  25.  
  26. public Ear   Ear{get; private set;}
  27. public Hand  Hand{get; private set;}
  28. public Eye   Eye{get; private set;}
  29.  
  30. public void SomethingHappendToBodyParts(BodyPart bodyPart)
  31. {
  32.     if(bodyPart is Ear)
  33.     {
  34.         string hearSounds = ((Ear)bodyPart).getSounds();
  35.         if(hearSounds.Contains("hallo"))
  36.         {
  37.             Hand.WaveHand();
  38.         }
  39.     }
  40.     if(bodyPart is Eye)
  41.     {
  42.         string seeSomething = ((Eye)bodyPart).HearSomething();
  43.        
  44.     }
  45.  
  46. }
  47.  
  48. }
  49.  
  50.  
  51.  
  52.  
  53.  
  54. class BodyPart
  55. {
  56.     private readonly Brain _brain;
  57.  
  58.     BodyPart(Brain brain)
  59.     {
  60.         _brain = brain;
  61.     }
  62.  
  63.     public void Changed()
  64.     {
  65.         _brain.SomethingHappendToBodyParts(this);
  66.     }
  67.  
  68. }
  69.  
  70. class Hand :BodyPart
  71. {
  72.     public Hand(Brain brain) : base(brain){}
  73.  
  74.     public void WaveHand()
  75.     {
  76.         Console.Writeline("My hand is waving.");
  77.     }
  78. }
  79.  
  80.  
  81. class Ear : BodyPart
  82. {
  83.     private string _sounds = string.Empty;
  84.  
  85.     Ear(Brain brain) : base(brain){}
  86.  
  87.     public string getSounds()
  88.     {
  89.         return _sounds;
  90.     }
  91.  
  92.     public void HearSomething()
  93.     {
  94.         Console.Writeline("Що ти чуєш?");
  95.         _sounds = Console.ReadLine();
  96.         Changed();
  97.     }
  98.  
  99. }
  100.  
  101.  
  102. class Eye : BodyPart
  103. {
  104.     private string whatISee = string.Empty;
  105.  
  106.     public void SeeSomething()
  107.     {
  108.         Console.Writeline("Що ти бачиш?");
  109.         whatISee = Console.ReadLine();
  110.         Changed();
  111.     }
  112.  
  113.     public string GetWhatISee()
  114.     {
  115.         return whatISee;       
  116.     }
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement