Take it easy, guys. The question was about design, not code. And now let's wait for Barry to clarify what he's stuck with.
yeah true.
Barry Brashear
Ranch Hand
Joined: Jun 05, 2001
Posts: 303
posted
0
Yes, my question was about class design not code.
thanks.
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35242
7
posted
0
What ideas have you had so far? Are you wondering about a particular design idea?
Piet Verdriet
Ranch Hand
Joined: Feb 25, 2006
Posts: 266
posted
0
Originally posted by Barry Brashear: Does anyone know how to go about designing a monopoly game for Java?
Thanks.
Try writing out the game and it's rules on a piece of paper (or just get the official manual). Then underline all the nouns and verbs on your piece of paper. The nouns are candidates for classes while the verbs are candidates for methods of those classes (of course, not all of them are relevant!).
Barry Brashear
Ranch Hand
Joined: Jun 05, 2001
Posts: 303
posted
0
Thanks. I guess that would include board, player, property, hotel, house, etc.
Piet Verdriet
Ranch Hand
Joined: Feb 25, 2006
Posts: 266
posted
0
Originally posted by Barry Brashear: Thanks. I guess that would include board, player, property, hotel, house, etc.
Among others, yes. And these are all classes. A "verb example": a player should have a method called move(...) to move from one section of the board to another.
Also, there could be a main class called Game, which holds the references to a Board instance, Player instances, a couple of Die (Dice) instances, etc. In that Game instance, you create a loop that keeps on looping giving each player on the board a turn to play. This loop is terminated whenever one of the players has won.
Good luck.
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35242
7
posted
0
While the verb/noun approach provides a first approximation at an object model, I'd say that it'd be a mistake to take its results too literally. A good object model isn't necessarily the one that mimics the real world perfectly - it needs to make sense for the application code.
E.g., I don't see what methods house or hotel objects would have. They differ in the amount of rent due, but that's an attribute of the property. So I might make the number of houses/hotels fields of a property object they belong to.
And there might be other objects that have no corresponding physical object.
You might find this discussion about modeling a tennis match interesting. [ July 11, 2008: Message edited by: Ulf Dittmer ]