Monday, February 17, 2020

design patterns - In some games, we just let the main() loop be the Player object or Table object?


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?




No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...