From 92fa284e20e70f2c264f8a3090132206595c57b0 Mon Sep 17 00:00:00 2001 From: Stanislav Mykhailenko Date: Sat, 15 Apr 2023 19:54:26 +0300 Subject: [PATCH] Revert "Update Lesson 4 Task 2" This reverts commit 944c693dc8809bd09f0fe534c4bc1304257655fc. --- Lesson_4/Task_2/Classes/FireMagic.cs | 16 ++++++++++++++ Lesson_4/Task_2/Classes/Magic.cs | 20 ++--------------- Lesson_4/Task_2/Classes/MagicType.cs | 22 ------------------- Lesson_4/Task_2/Classes/WaterMagic.cs | 16 ++++++++++++++ Lesson_4/Task_2/Interfaces/IMagic.cs | 2 +- .../{IMagicType.cs => IMagicClass.cs} | 6 ++--- Lesson_4/Task_2/Program.cs | 13 ++--------- 7 files changed, 40 insertions(+), 55 deletions(-) create mode 100644 Lesson_4/Task_2/Classes/FireMagic.cs delete mode 100644 Lesson_4/Task_2/Classes/MagicType.cs create mode 100644 Lesson_4/Task_2/Classes/WaterMagic.cs rename Lesson_4/Task_2/Interfaces/{IMagicType.cs => IMagicClass.cs} (63%) diff --git a/Lesson_4/Task_2/Classes/FireMagic.cs b/Lesson_4/Task_2/Classes/FireMagic.cs new file mode 100644 index 0000000..8842b59 --- /dev/null +++ b/Lesson_4/Task_2/Classes/FireMagic.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using Open_Closed.Interfaces; + +namespace Open_Closed.Classes +{ + public class FireMagic : IMagicClass + { + public int MagicValue { get { return 150; } } + public string MagicType { get { return "fire"; } } + } +} diff --git a/Lesson_4/Task_2/Classes/Magic.cs b/Lesson_4/Task_2/Classes/Magic.cs index 06c3731..0024c62 100644 --- a/Lesson_4/Task_2/Classes/Magic.cs +++ b/Lesson_4/Task_2/Classes/Magic.cs @@ -10,25 +10,9 @@ namespace Open_Closed.Classes { public class Magic : IMagic { - private List MagicTypes; - - public Magic(List magicTypes) + public void CountYourMagic(IMagicClass MagicClass) { - MagicTypes = magicTypes; - } - - public void CountYourMagic(int magic) - { - foreach(var magicType in MagicTypes) - { - if(magic == magicType.Value) - { - Console.WriteLine($"Wow, your magic is {magicType.Name}!"); - return; - } - } - - Console.WriteLine("I understand you..."); + Console.WriteLine($"Your magic is {MagicClass.MagicType}."); } } } diff --git a/Lesson_4/Task_2/Classes/MagicType.cs b/Lesson_4/Task_2/Classes/MagicType.cs deleted file mode 100644 index de9a5df..0000000 --- a/Lesson_4/Task_2/Classes/MagicType.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -using Open_Closed.Interfaces; - -namespace Open_Closed.Classes -{ - public class MagicType : IMagicType - { - public string Name { get; set; } - public int Value { get; set; } - - public MagicType(string name, int value) - { - Name = name; - Value = value; - } - } -} diff --git a/Lesson_4/Task_2/Classes/WaterMagic.cs b/Lesson_4/Task_2/Classes/WaterMagic.cs new file mode 100644 index 0000000..aef7e32 --- /dev/null +++ b/Lesson_4/Task_2/Classes/WaterMagic.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using Open_Closed.Interfaces; + +namespace Open_Closed.Classes +{ + public class WaterMagic : IMagicClass + { + public int MagicValue { get { return 50000000; } } + public string MagicType { get { return "water"; } } + } +} diff --git a/Lesson_4/Task_2/Interfaces/IMagic.cs b/Lesson_4/Task_2/Interfaces/IMagic.cs index cc63226..417e11d 100644 --- a/Lesson_4/Task_2/Interfaces/IMagic.cs +++ b/Lesson_4/Task_2/Interfaces/IMagic.cs @@ -8,6 +8,6 @@ namespace Open_Closed.Interfaces { public interface IMagic { - void CountYourMagic(int magic); + void CountYourMagic(IMagicClass MagicClass); } } diff --git a/Lesson_4/Task_2/Interfaces/IMagicType.cs b/Lesson_4/Task_2/Interfaces/IMagicClass.cs similarity index 63% rename from Lesson_4/Task_2/Interfaces/IMagicType.cs rename to Lesson_4/Task_2/Interfaces/IMagicClass.cs index 64c9348..7a44e78 100644 --- a/Lesson_4/Task_2/Interfaces/IMagicType.cs +++ b/Lesson_4/Task_2/Interfaces/IMagicClass.cs @@ -6,9 +6,9 @@ using System.Threading.Tasks; namespace Open_Closed.Interfaces { - public interface IMagicType + public interface IMagicClass { - string Name { get; } - int Value { get; } + int MagicValue { get; } + string MagicType { get; } } } diff --git a/Lesson_4/Task_2/Program.cs b/Lesson_4/Task_2/Program.cs index e3fa27b..3177504 100644 --- a/Lesson_4/Task_2/Program.cs +++ b/Lesson_4/Task_2/Program.cs @@ -1,13 +1,4 @@ using Open_Closed.Classes; -List magicTypes = new List() -{ - new MagicType("Fire Magic", 150), - new MagicType("Water Magic", 50000000) -}; - -Magic magic = new Magic(magicTypes); - -magic.CountYourMagic(150); -magic.CountYourMagic(50000000); -magic.CountYourMagic(12345); +(new Magic()).CountYourMagic(new FireMagic()); +(new Magic()).CountYourMagic(new WaterMagic());