Update Lesson 4 Task 2

This commit is contained in:
Stanislav Mykhailenko 2023-04-13 18:16:26 +03:00
parent 20d02a283a
commit 944c693dc8
GPG key ID: 1E95E66A9C9D6A36
7 changed files with 55 additions and 40 deletions

View file

@ -1,16 +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 FireMagic : IMagicClass
{
public int MagicValue { get { return 150; } }
public string MagicType { get { return "fire"; } }
}
}

View file

@ -10,9 +10,25 @@ namespace Open_Closed.Classes
{ {
public class Magic : IMagic public class Magic : IMagic
{ {
public void CountYourMagic(IMagicClass MagicClass) private List<MagicType> MagicTypes;
public Magic(List<MagicType> magicTypes)
{ {
Console.WriteLine($"Your magic is {MagicClass.MagicType}."); 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...");
} }
} }
} }

View file

@ -0,0 +1,22 @@
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;
}
}
}

View file

@ -1,16 +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 WaterMagic : IMagicClass
{
public int MagicValue { get { return 50000000; } }
public string MagicType { get { return "water"; } }
}
}

View file

@ -8,6 +8,6 @@ namespace Open_Closed.Interfaces
{ {
public interface IMagic public interface IMagic
{ {
void CountYourMagic(IMagicClass MagicClass); void CountYourMagic(int magic);
} }
} }

View file

@ -6,9 +6,9 @@ using System.Threading.Tasks;
namespace Open_Closed.Interfaces namespace Open_Closed.Interfaces
{ {
public interface IMagicClass public interface IMagicType
{ {
int MagicValue { get; } string Name { get; }
string MagicType { get; } int Value { get; }
} }
} }

View file

@ -1,4 +1,13 @@
using Open_Closed.Classes; using Open_Closed.Classes;
(new Magic()).CountYourMagic(new FireMagic()); List<MagicType> magicTypes = new List<MagicType>()
(new Magic()).CountYourMagic(new WaterMagic()); {
new MagicType("Fire Magic", 150),
new MagicType("Water Magic", 50000000)
};
Magic magic = new Magic(magicTypes);
magic.CountYourMagic(150);
magic.CountYourMagic(50000000);
magic.CountYourMagic(12345);