apieceoffruit

World

May 19th, 2021 (edited)
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.70 KB | None | 0 0
  1. public class Tank : Unit
  2. {
  3.     public void DoSomething() => World.CreateTank();
  4. }
  5.  
  6. public class Unit
  7. {
  8.     protected readonly World World;
  9.     public Unit(World world) => this.World = world;
  10. }
  11.  
  12.  
  13. public class World
  14. {
  15.     public World()
  16.     {
  17.         _units = new Units();
  18.         _unitFactory = new UnitFactory(this);
  19.     }
  20.  
  21.     public void CreateTank() => _units.Add(_unitFactory.CreateTank());
  22.    
  23.     UnitFactory _unitFactory;
  24.     Units _units;
  25.    
  26. }
  27.  
  28.  
  29. public class UnitFactory
  30. {
  31.     public void Create(string name) => new Unit(_world);
  32.     public void CreateTank() => new Tank(_world);
  33.  
  34.     readonly World _world;
  35.     public UnitFactory(World world) => this._world = world;
  36. }
  37.  
Add Comment
Please, Sign In to add comment