parent
260fc90457
commit
92fa284e20
7 changed files with 40 additions and 55 deletions
16
Lesson_4/Task_2/Classes/FireMagic.cs
Normal file
16
Lesson_4/Task_2/Classes/FireMagic.cs
Normal file
|
@ -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"; } }
|
||||
}
|
||||
}
|
|
@ -10,25 +10,9 @@ namespace Open_Closed.Classes
|
|||
{
|
||||
public class Magic : IMagic
|
||||
{
|
||||
private List<MagicType> MagicTypes;
|
||||
|
||||
public Magic(List<MagicType> 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}.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
16
Lesson_4/Task_2/Classes/WaterMagic.cs
Normal file
16
Lesson_4/Task_2/Classes/WaterMagic.cs
Normal file
|
@ -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"; } }
|
||||
}
|
||||
}
|
|
@ -8,6 +8,6 @@ namespace Open_Closed.Interfaces
|
|||
{
|
||||
public interface IMagic
|
||||
{
|
||||
void CountYourMagic(int magic);
|
||||
void CountYourMagic(IMagicClass MagicClass);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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; }
|
||||
}
|
||||
}
|
|
@ -1,13 +1,4 @@
|
|||
using Open_Closed.Classes;
|
||||
|
||||
List<MagicType> magicTypes = new List<MagicType>()
|
||||
{
|
||||
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());
|
||||
|
|
Reference in a new issue