Skip to content

Commit

Permalink
[#9]: add dice
Browse files Browse the repository at this point in the history
  • Loading branch information
3k-dome committed Apr 24, 2023
1 parent d7ec0e5 commit 93b6eca
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
10 changes: 10 additions & 0 deletions catan-lib/Interfaces/IDice.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace CatanLib.Interfaces
{
public interface IDice
{
Random Random { get; }
int Rolled { get; }
int Roll();
int RollTwice();
}
}
28 changes: 28 additions & 0 deletions catan-lib/Parts/Dice.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using CatanLib.Interfaces;

namespace CatanLib.Parts
{
public class Dice : IDice
{
public Random Random { get; init; }

public int Rolled { get; private set; }

public Dice(int seed)
{
Random = new(seed);
}

public int Roll()
{
Rolled = Random.Next(1, 7);
return Rolled;
}

public int RollTwice()
{
Rolled = Random.Next(1, 7) + Random.Next(1, 7);
return Rolled;
}
}
}

0 comments on commit 93b6eca

Please sign in to comment.