[Solved] Monopoly Implementing Rules


Seems like your squares ought to consist of a type hierarchy.

Square

  • Card-Draw
    • Chance
    • Community Chest
  • Tax/GO
  • Jail
  • Ownable
    • Utility
    • Railroad
    • Colored

All of these will have a polymorphic method

virtual void VisitFrom(int diceRoll, Player activePlayer);

For example, Utility’s implementation might be.

virtual void VisitFrom(int diceRoll, Player activePlayer)
{
    if (owner == Bank)
        activePlayer.offerProperty(this, 150);
    else if (activePlayer != owner)
        activePlayer.Pay(owner, ((otherUtility.owner == owner)? 10: 4) * diceRoll);
}

Oh the other hand, both players should be instances of the same class.

You need separate classes for objects with separate behavior. Use instances when objects act alike.

Of course you also need to associate Colored instance into ColorGroups to give bonuses when the same player owns them all.

2

solved Monopoly Implementing Rules