Skip to content

Commit

Permalink
[#9]: update interface for dice, catan & player
Browse files Browse the repository at this point in the history
  • Loading branch information
3k-dome committed May 8, 2023
1 parent 23b3975 commit b5c5e22
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 41 deletions.
1 change: 1 addition & 0 deletions catan-lib/Interfaces/Components/ICatan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace CatanLib.Interfaces.Components;
public interface ICatan
{
IDice Dice { get; }
IBank Bank { get; }
Board Board { get; }
IEnumerable<IPlayer> Players { get; }
IPlayer CurrentPlayer { get; }
Expand Down
6 changes: 4 additions & 2 deletions catan-lib/Interfaces/Components/IDice.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
namespace CatanLib.Interfaces.Components
using CatanLib.Interfaces.Interaction;

namespace CatanLib.Interfaces.Components
{
public interface IDice
public interface IDice : IVectorizableComponent
{
Random Random { get; init; }
int Rolled { get; }
Expand Down
40 changes: 1 addition & 39 deletions catan-lib/Interfaces/Components/IPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,7 @@

namespace CatanLib.Interfaces.Components;

public interface IPlayer : IVectorizableComponent
public interface IPlayer : IResourceCollection, IPieceCollection, IVectorizableComponent
{
PlayerNumber Number { get; set; }
Dictionary<ResourceType, int> Resources { get; }

void UseResource(ResourceType resource)
{
if (Resources[resource] <= 0)
{
throw new Exception("Player can't spend any more of this Resource!");
}

Resources[resource]--;
}

void UseResources(IEnumerable<ResourceType> resources)
{
foreach (ResourceType resource in resources)
{
UseResource(resource);
}
}

void GainResource(ResourceType resource)
{
Resources[resource]++;
}

void GainResources(IEnumerable<ResourceType> resources)
{
foreach (ResourceType resource in resources)
{
GainResource(resource);
}
}

bool HasResources(IEnumerable<ResourceType> resources)
{
return resources.GroupBy(resource => resource)
.All(group => Resources[group.Key] >= group.Count());
}
}

0 comments on commit b5c5e22

Please sign in to comment.