Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

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();.

share|improve this answer
1  
Be wary of the "god object," though: gamedev.stackexchange.com/questions/27459/… –  Daniel Ward Jan 1 at 4:16
    
@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! –  Amplify91 Jan 1 at 21:14
    
I agree with you. No harm meant... My intent was more to educate the asker than the answerer. –  Daniel Ward 10 hours ago
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.