mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-22 07:10:42 -08:00
28 lines
724 B
C#
28 lines
724 B
C#
using BugGame.Resources;
|
|
|
|
namespace BugGame.Parts;
|
|
|
|
internal abstract class ParentPart : Part
|
|
{
|
|
public ParentPart(Message addedMessage, Message duplicateMessage)
|
|
: base(addedMessage, duplicateMessage)
|
|
{
|
|
}
|
|
|
|
public bool TryAdd(IPart part, out Message message)
|
|
=> (part.GetType() == GetType(), IsPresent) switch
|
|
{
|
|
(true, _) => TryAdd(out message),
|
|
(false, false) => ReportDoNotHave(out message),
|
|
_ => TryAddCore(part, out message)
|
|
};
|
|
|
|
protected abstract bool TryAddCore(IPart part, out Message message);
|
|
|
|
private bool ReportDoNotHave(out Message message)
|
|
{
|
|
message = Message.DoNotHaveA(this);
|
|
return false;
|
|
}
|
|
}
|