oop


Players and deck methods in a card game


I'm programming a card game (of Uno / Mau Mau type) and I have this design problem:
The deck contains two stacks of cards, one of them shows faces, the other shows backs. When a game is in progress and a player throws a card, it should go onto the "faces" stack. However, when the game is finished, the cards of the last player should go back onto the "backs" stack.
1) Should the deck have two methods for adding cards (addToFacesStack and addToBacksStack)
or
2) Should the deck have an addCards method and decide itself which stack the cards should go onto (the deck would have to know the state of the game - in progress/finished)?
Also, when the game is in progress and a player (who knows the rules and selects cards to play accordingly) throws card(s) onto the "faces" stack, should the deck "re-check" whether the player's move is valid?
Thanks in advance for your suggestions!
Caroline
I think you should be asking the question: should the model know about the game logic or just the state of the game?
If YES, then you need to include the game logic inside your model, hence you can have only the addCards method, and the Deck will decide where to add the card(s). But, in this case the game model and game logic are tightly coupled. If you were to use the same model for another variation of the game (with a different logic), this option would not be appropriate.
If NO, then you can follow the Boundary - Control - Entity design pattern. Here, you need to have separate methods for adding cards to the first or second stack. And encode the game logic into your controller objects, which would know the rules of the game. Using this pattern, you can reuse the same model and just employ different controllers based on the game being played.
Regarding your question:
Also, when the game is in progress and a player (who knows the rules and selects cards to play accordingly) throws card(s) onto the "faces" stack, should the deck "re-check" whether the player's move is valid?
In this case, you can have a controller that will check whether the move is valid or not. No need to encode the logic inside the model.

Related Links

Call an overridden method from super class in typescript
Inheritance over composition
What kind of pattern design would apply?
What is this common hierarchy mistake called?
Change header tab stops in Microsoft Word
How to circumvent no static property inheritance in OOP?
Models getting out of hand
How to temporarily circumvent domain object's creation contracts when restoring application from backup?
How to start with the design of an OOP MVC app
injecting the correct type to my business class using Autofac
Subtypes of an interface only compatible with a subtype of another interface
Simple game design: I'm scared of tons of loops
Getting a 'nil' value when attaching an addEventListener method to a created Object
Multiple Dispatch: A conceptual necessity?
CIL instructions unexpected return value
Design pattern for translating multiple data-formats from multiple sources to a single format

Categories

HOME
javafx
optimization
redux
intellij-idea
salesforce
customization
casting
skypedeveloper
richtextbox
servicenow
doctrine2
samsung-gear-s2
core-data
taxonomy
minimagick
opengraph
quality-center
functional-dependencies
akavache
traveling-salesman
cloudformation
mex
bytebuffer
delphi-2010
javafxports
perf
hippocms
azure-storage-files
anypoint-studio
ngrok
idea-plugin
google-chrome-console
rexx
python-venv
cakephp-3.2
bootstrap-carousel
gradlew
api-key
import.io
visio-2010
spring-social-twitter
jira-agile
mate-desktop
git-cherry-pick
supervised-learning
jmap
datamodel
gtkwave
android-contentresolver
controlpanel
azure-mobile-app
playn
genome
nfa
wingdb
mri
cl.exe
javadb
pnunit
livescript
azure-worker-roles
atg-dynamo
nspopupbutton
dateadd
rda
smartxls
new-operator
class-library
node-mongodb-native
acrofields
mixradio
logo-lang
mobile-robots
custom-cursor
xcode4.6.3
databus
erlide
optimistic-concurrency
sqlbuddy
log-shipping
recess
opendir
fxcopcmd
conditional-operator
datarelation
dongle
morfik
atmega16
wtsapi32
j++

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html