Quantcast
Channel: User Álvaro García - Software Engineering Stack Exchange
Viewing all articles
Browse latest Browse all 41

Doubts how to design a card game in DDD

$
0
0

I was thinking how to design a simple cards game, like poker, in a DDD way, but I am not sure about some points.

Basically what I want is this, but I will try to simplify the problems that I have.

  • I have a match in which I can add players.
  • A match is played in 10 rounds.
  • Each player play in the round in its turn (for simplify, one turn per round). In this turn it can request card, throw card, bet and so on.
  • A match is attended by an arbitrator, that is who shuffle the cards, tell when a player starts its turn and finish it, give the cards to the player... etc.
  • In each round, I want to know the time that a player spend in its turn. And also I want to know the total time of a round in the match.

I will expose the model that I would think and later i will tell my doubts.

Class match:

    Class Match    {        long Id;        DateTime Date;        string Description;        List<Player> Players;        List<Round> Rounds;        public void Start() {}        public void Finish() {}        .....    }Class Player(){    long Id;    string Name;    List<Round> Round;    public void StartTurn() {}    public void FinishTurn() {}    public void Bet() {}    public void RequestCard() {}    public void ThrowCard() {}    public void Bet() {}    .....}Class Round{    long Id;    long TimeInSeconds;    public StartCountingTime() {}    public StopCountingTime() {}}class Arbitrator(){    public void shuffle() {}    public void AsignTurnToPlayer() {}    public void GiveCardToPlayer() {}    public void StartGame() {}    public void FinishGame() {}    ....}

I think this solution because in this way, when a player gets the turn, they can call the method StartCountingTime() in the Round entity and call StopCountingTime() when they finishes they turn. It is easy, but I am not sure if the player should have the responsability to count the time, the player should play only.

Then I was thinking since the Arbitrator decides when the player starts and stops its turn, it could manage the time in the rounds. But in this case, where should I declare the Round objects for the players? And thinking again, is the Arbitrator entity the responsible for controlling the time, or only responsible for making players follow the rules and coordinate the match?

My main problem is with control of the time spending in the rounds. How to handle it, where to declare the Round objects and related it with the Match and with the Players.

And the second doubt is with the Match entity, really in my code I declare two methods to start and stop the game, but this perhaps it is more a responsibility of the Arbitrator than the game, but if the Match entity has not methods, it would be an anemic object, but really I need this object to can store the Id, the description and to know the players that plays in the match.

So in summary, my main question is who has the responsibility to control the time in the rounds. And the second question is whether the Match entity could be seen as an anemic entity or if it is correct in this way.


Viewing all articles
Browse latest Browse all 41