Class PlayerBuilder
- Namespace
- WitShells.DesignPatterns.Core
Concrete builder that constructs a Player using a fluent API.
Call the Set* methods in any order, then call Build() to get the result.
public class PlayerBuilder : Builder<Player>, IBuilder<Player>
- Inheritance
-
PlayerBuilder
- Implements
- Inherited Members
Examples
var player = new PlayerBuilder()
.SetName("Hero")
.SetHealth(100)
.SetSpeed(5.5f)
.Build();
Methods
Build()
Finalises and returns the constructed object.
public override Player Build()
Returns
SetHealth(int)
Sets the player's starting health.
public PlayerBuilder SetHealth(int health)
Parameters
healthintHealth point value (e.g. 100).
Returns
SetName(string)
Sets the player's name.
public PlayerBuilder SetName(string name)
Parameters
namestringDisplay name for the player.
Returns
SetSpeed(float)
Sets the player's movement speed.
public PlayerBuilder SetSpeed(float speed)
Parameters
speedfloatSpeed in units per second.