Created
October 17, 2019 10:09
-
-
Save HolyMonkey/6f3df5a210c7f26a723c76914c8906f4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
namespace _12_Builder | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var unitBuilder = new UnitBuilder(); | |
unitBuilder.WithPhysicalArmor().WithMagicalArmor(). | |
} | |
} | |
class UnitBuilder | |
{ | |
private GameObject _gameObject; | |
private IArmor _armor; | |
public UnitBuilder() | |
{ | |
_gameObject = new GameObject(); | |
} | |
public UnitBuilder WithPhysicalArmor() | |
{ | |
_armor = new PhysicalArmor(); | |
return this; | |
} | |
public UnitBuilder WithMagicalArmor() | |
{ | |
_armor = new MagicArmor(); | |
return this; | |
} | |
public UnitBuilder MovingOnPath() | |
{ | |
_gameObject.Components.Add(new PathMovement()); | |
return this; | |
} | |
public UnitBuilder Flying() | |
{ | |
_gameObject.Components.Add(new FlyMovement()); | |
return this; | |
} | |
public GameObject Create() | |
{ | |
_gameObject.Components.Add(new Health() | |
{ | |
Armor = _armor | |
}); | |
return _gameObject; | |
} | |
} | |
class GameObject | |
{ | |
public List<IComponent> Components; | |
} | |
interface IComponent | |
{ | |
void Start(); | |
void Update(); | |
} | |
class Health : IComponent | |
{ | |
public IArmor Armor; | |
} | |
interface IArmor | |
{ | |
int ProccessDamage(int damage); | |
} | |
class MagicArmor : IArmor | |
{ | |
} | |
class PhysicalArmor : IArmor | |
{ | |
} | |
abstract class Movement : IComponent | |
{ | |
} | |
class PathMovement : Movement | |
{ | |
} | |
class FlyMovement : Movement | |
{ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment