mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-23 07:29:02 -08:00
Add Bug and conecpt of completeness
This commit is contained in:
13
16_Bug/csharp/Bug.cs
Normal file
13
16_Bug/csharp/Bug.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using BugGame.Parts;
|
||||
using BugGame.Resources;
|
||||
|
||||
namespace BugGame;
|
||||
|
||||
internal class Bug
|
||||
{
|
||||
private readonly Body _body = new();
|
||||
|
||||
public bool IsComplete => _body.IsComplete;
|
||||
|
||||
public bool TryAdd(IPart part, out Message message) => _body.TryAdd(part, out message);
|
||||
}
|
||||
@@ -13,6 +13,8 @@ internal class Body : ParentPart
|
||||
{
|
||||
}
|
||||
|
||||
public override bool IsComplete => _neck.IsComplete && _tail.IsComplete && _legs.IsComplete;
|
||||
|
||||
protected override bool TryAddCore(IPart part, out Message message)
|
||||
=> part switch
|
||||
{
|
||||
|
||||
@@ -11,6 +11,8 @@ internal class Head : ParentPart
|
||||
{
|
||||
}
|
||||
|
||||
public override bool IsComplete => _feelers.IsComplete;
|
||||
|
||||
protected override bool TryAddCore(IPart part, out Message message)
|
||||
=> part switch
|
||||
{
|
||||
|
||||
@@ -3,4 +3,5 @@ namespace BugGame.Parts;
|
||||
internal interface IPart
|
||||
{
|
||||
string Name { get; }
|
||||
bool IsComplete { get; }
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@ internal class Neck : ParentPart
|
||||
{
|
||||
}
|
||||
|
||||
public override bool IsComplete => _head.IsComplete;
|
||||
|
||||
protected override bool TryAddCore(IPart part, out Message message)
|
||||
=> part switch
|
||||
{
|
||||
|
||||
@@ -13,6 +13,8 @@ internal class Part
|
||||
_duplicateMessage = duplicateMessage;
|
||||
}
|
||||
|
||||
public virtual bool IsComplete => IsPresent;
|
||||
|
||||
protected bool IsPresent { get; private set; }
|
||||
|
||||
public string Name => GetType().Name;
|
||||
|
||||
@@ -16,6 +16,8 @@ internal class PartCollection
|
||||
_fullMessage = fullMessage;
|
||||
}
|
||||
|
||||
public bool IsComplete => _count == _maxCount;
|
||||
|
||||
public bool TryAddOne(out Message message)
|
||||
{
|
||||
if (_count < _maxCount)
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
using BugGame.Parts;
|
||||
|
||||
namespace BugGame.Resources;
|
||||
|
||||
internal class Message
|
||||
|
||||
Reference in New Issue
Block a user