Results 1 to 5 of 5
- 03-14-2011, 06:24 PM #1
Member
- Join Date
- Jun 2010
- Posts
- 5
- Rep Power
- 0
Class Design Problems (BlackJack)
Hello Java Forums, I am currently trying to build a simple blackjack game as part of my plans for march break. However, I am having problems in creating an optimal class design.
Designing classes has always been difficult and a challenge for me, especially during my high school comp sci classes.
Attached is my current UML diagram solution. Extending from the blackJackGame class are classes playerManager, gameRound, and cardDeck.
playerManager and cardDeck contain arrays of players and card objects respectively. The player class inherits botplayer, which is an AI controlled player.
I am unsure whether having a gameRound object is necessary (since one round of the game is played each time).
If anybody could also please offer some insight/advice on properly designing a program, I would highly appreciate it. I've tried looking for other resources online but have had no luck.
- 03-15-2011, 02:01 PM #2
Member
- Join Date
- Jun 2010
- Posts
- 5
- Rep Power
- 0
Bump, is there anybody that can offer some help? D:
- 03-15-2011, 02:23 PM #3
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Just taking your Player corner, I'd suggest an interface there.
Or, put another way, you have a Player class. You also then have a RealPlayer class that extends that, and your BotPlayer class that also extends it.
Having your Player class extend botPlayer makes no sense.
This means that only Player is referenced by the other game objects.
As for gameRound, I suspect your player manager will handle whose turn it is next, and your game object will handle whether anyone has won. So I don't see that there's much for the game round to do.
- 03-16-2011, 02:31 AM #4
Member
- Join Date
- Jun 2010
- Posts
- 5
- Rep Power
- 0
Thank you for your help. I've refined the design, and eliminated the gameRound object like you suggested, and have RealPlayer and BotPlayer extend from a Player class.
I am debating whether to make my Player class abstract. The botPlayer contains a very simple AI to determine when to hit/stay. Would this be a good idea?
Also, would it be helpful to create a separate object containing the card hands for an individual player? I still feel that there is something fundamentally wrong about my design, as it isn't "clean".Last edited by ConMan; 03-16-2011 at 02:44 AM.
- 03-16-2011, 08:38 AM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Well, why does the blackJackGame need to reference botPlayer at all?
I would assume it was down to the playerManager to assign bots and real players, or even some sort of player factory (though that might be going too far in this case).
From that diagram Players already have cards...that line I took to be a one-to-many.
As I said above, a Player will probably (in Java) be best done as an interface, so simply define its methods.
You could probably get rid of the cardDeck as well, since that would be represented by a one-to-many relationship from blackJackGame to Card.
Similar Threads
-
organisational problems for web design
By jery.martin in forum Advanced JavaReplies: 7Last Post: 04-28-2010, 02:24 PM -
class design
By dinosoep in forum New To JavaReplies: 3Last Post: 12-07-2009, 10:20 AM -
Problems dragging sql server 2008 tables to design viewer in NetBeans 6.5
By mosbos in forum NetBeansReplies: 0Last Post: 04-05-2009, 01:22 PM -
Problems with JFrame losing the Design view
By chris@gaiag.net in forum NetBeansReplies: 7Last Post: 07-23-2008, 07:35 AM -
Pls HeLp Me (Design a class named Fan)
By faw in forum Advanced JavaReplies: 5Last Post: 04-21-2008, 07:25 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks