mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-22 23:26:40 -08:00
Add parts and messages
This commit is contained in:
25
16_Bug/csharp/Parts/Body.cs
Normal file
25
16_Bug/csharp/Parts/Body.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using BugGame.Resources;
|
||||
|
||||
namespace BugGame.Parts;
|
||||
|
||||
internal class Body : ParentPart
|
||||
{
|
||||
private readonly Neck _neck = new();
|
||||
private readonly Tail _tail = new();
|
||||
private readonly Legs _legs = new();
|
||||
|
||||
public Body()
|
||||
: base(Message.BodyAdded, Message.BodyNotNeeded)
|
||||
{
|
||||
}
|
||||
|
||||
protected override bool TryAddCore(IPart part, out Message message)
|
||||
=> part switch
|
||||
{
|
||||
Neck => _neck.TryAdd(out message),
|
||||
Head or Feeler => _neck.TryAdd(part, out message),
|
||||
Tail => _tail.TryAdd(out message),
|
||||
Leg => _legs.TryAddOne(out message),
|
||||
_ => throw new NotSupportedException($"Can't add a {part.Name} to a {Name}.")
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user