Tech Off Post

Single Post Permalink

View Thread: Yet another C# dice question.
  • User profile image

    I would recommend making a dice object. And a DiceCollection that allow you to look at the dice in different ways like:

    int sides = 6;
    int numberOfDice = 5;
    //Provide overload also for rolling dice of mix # of sides as well?
    DiceCollection dCollection = new DiceCollection
    (sides, numberOfDice);


    OO is a much better design. Even with the above snippet you can see how you can abstract away alot of the work Pop shows.

    With a mix collection of dice (20 sided, 6 sided etc) Collection.Roll() would call the childs Roll method and the child would store it result. All Results methods would be a matter of iterating over the children and performing some predicate on them. (Result >= expected)

    The to make the game you suggest Each player would have a DiceCollection and it would be a simple matter of checking the results of everyone playing and displaying however you want.