Created
October 2, 2018 05:31
-
-
Save LeviVisser/1a5df75fbb755d76945f5b2fab41d01f to your computer and use it in GitHub Desktop.
This file contains 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
/// <summary> | |
/// Director class | |
/// </summary> | |
class Director : MonoBehaviour { | |
private AbstractShipBuilder _shipBuilder; | |
public void SetShipBuilder(AbstractShipBuilder builder) | |
{ | |
_shipBuilder = builder; | |
} | |
public BaseShip GetBaseShip() | |
{ | |
return _shipBuilder.GetBaseShip(); | |
} | |
public void ConstructBaseShip(ShipStats stats, ShipMovementComponent movementComp, EngineComponent engineComp) | |
{ | |
_shipBuilder.CreateNewBaseShip(); | |
_shipBuilder.BuildStats(stats); | |
_shipBuilder.BuildEngineComponent(engineComp); | |
_shipBuilder.BuildMovementComponent(movementComp); | |
} | |
} | |
/// <summary> | |
/// Abstract builder | |
/// </summary> | |
abstract class AbstractShipBuilder { | |
protected BaseShip baseShip; | |
public BaseShip GetBaseShip() | |
{ | |
return baseShip; | |
} | |
public void CreateNewBaseShip() | |
{ | |
baseShip = new BaseShip(); | |
} | |
public abstract void BuildStats(ShipStats stats); | |
public abstract void BuildMovementComponent(ShipMovementComponent movementComp); | |
public abstract void BuildEngineComponent(EngineComponent engineComp); | |
} | |
/// <summary> | |
/// Concrete Ship builder | |
/// </summary> | |
class ConcreteShipBuilder : AbstractShipBuilder { | |
public override void BuildStats(ShipStats stats) | |
{ | |
baseShip.SetStats(stats); | |
} | |
public override void BuildMovementComponent(ShipMovementComponent movementComp) | |
{ | |
baseShip.SetMovementComponent(movementComp); | |
} | |
public override void BuildEngineComponent(EngineComponent engineComp) | |
{ | |
baseShip.SetEngineComponent(engineComp); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment