0
\$\begingroup\$

I was thinking that let's say if there is a game of Blackjack or MasterMind, then we should have a class called Dealer or ComputerPal, which is how the computer interact with us (as a dealer for Blackjack or as the person giving hints for MasterMind).

And then there should be a Player object, and the way to play one game is

aPlayer.playGame

but I noticed that a book was just using the main() loop to act as the player (or as the Controller of the game), calling the Dealer methods to dealer the cards, ask for player's action, etc...

1) Is this just a lazy way to model all the proper objects?

2) If more objects are to be added, who should call the aDealer.dealCards and then ask for aPlayer.askForAction? (because it is strange to let the Player handle all the logical steps). Should there be a Table object that handle all these logic and then to play one round of game, use aTable.playGame? What is a good object design for such game?

\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

Having the Player class run the game would be a bad way to go about things. As the book you read was probably explaining, you should have some sort of game loop that handles updating logic and drawing the graphics. To answer your questions:

  1. No, this isn't the correct way. You would not want to give the Player object responsibility over the entire game as it is outside of the scope of a "player".

  2. The game loop should call an update function periodically. Inside this update() is where you should call all of your logical functions. Like this:

    void update(){  
        aDealer.dealCards();  
        aPlayer.playHand();  
        aOpponent.playHand();  
    }
    

Responsibility for managing the game belongs outside of the Player class. Perhaps consider writing a GameManager class with a similar update function. In your game loop, call aGameManager.update();.

\$\endgroup\$
3
  • 1
    \$\begingroup\$ Be wary of the "god object," though: gamedev.stackexchange.com/questions/27459/… \$\endgroup\$ Commented Jan 1, 2014 at 4:16
  • \$\begingroup\$ @DanielWard, excellent question that you linked to. However, please don't be too harsh on my simple design advice and look at the scope of this question. For a card game made by a single, somewhat novice programmer, this simple structure would be enough to finish a functional game. I did not mean to suggest using a "GameManager" was the way that all game engines should be designed. Again, the question you linked to above is a much better resource for someone more interested in proper architecture. Thank you! \$\endgroup\$
    – Amplify91
    Commented Jan 1, 2014 at 21:14
  • \$\begingroup\$ I agree with you. No harm meant... My intent was more to educate the asker than the answerer. \$\endgroup\$ Commented Apr 15, 2014 at 22:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .