I often see very different implementations of the Model View controller template and fully understand that you should adapt and use what best suits your needs, but I was wondering what would be the advantages / disadvantages / best practices of storing a simple game of logic on the controller or models?
In essence, is this the right way I should do this?
for this simple example, the player takes damage, and I have listed three possible ways to deal with it:
1.
Controller or:
_model.playerDamage - 15; if (_model.playerDamage <= 0){ _model.playerLives --; _model.restartLevel(); }
2.
controller:
_model.playerDamage = 15;
Model:
function set playerDamage(value:int){ playerDamage = value; updatePlayer(); } function updatePlayer():void{ if (playerDamage<=0){ palyerLives --; restartLevel(); } }
3.
controller:
_model.playerDamage = 15; _model.addEventListener('playerChange', checkPlayerStatus); function checkPlayerStatus(e:Event):void{ if (_model.playerDamage<=0){ _model.playerLives --; _model.restartLevel(); } }
Model:
function set playerDamage(value:int){ playerDamage = value; dispatchEvent(new Event('playerChange')); }
source share