Results 1 to 5 of 5
  1. #1
    ConMan is offline Member
    Join Date
    Jun 2010
    Posts
    5
    Rep Power
    0

    Default 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.
    Attached Thumbnails Attached Thumbnails Class Design Problems (BlackJack)-design.jpg  

  2. #2
    ConMan is offline Member
    Join Date
    Jun 2010
    Posts
    5
    Rep Power
    0

    Default

    Bump, is there anybody that can offer some help? D:

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,742
    Rep Power
    19

    Default

    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.

  4. #4
    ConMan is offline Member
    Join Date
    Jun 2010
    Posts
    5
    Rep Power
    0

    Default

    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".
    Attached Thumbnails Attached Thumbnails Class Design Problems (BlackJack)-design2.jpg  
    Last edited by ConMan; 03-16-2011 at 02:44 AM.

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,742
    Rep Power
    19

    Default

    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

  1. organisational problems for web design
    By jery.martin in forum Advanced Java
    Replies: 7
    Last Post: 04-28-2010, 02:24 PM
  2. class design
    By dinosoep in forum New To Java
    Replies: 3
    Last Post: 12-07-2009, 10:20 AM
  3. Replies: 0
    Last Post: 04-05-2009, 01:22 PM
  4. Problems with JFrame losing the Design view
    By chris@gaiag.net in forum NetBeans
    Replies: 7
    Last Post: 07-23-2008, 07:35 AM
  5. Pls HeLp Me (Design a class named Fan)
    By faw in forum Advanced Java
    Replies: 5
    Last Post: 04-21-2008, 07:25 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •