I have been trying for a little while to wrap my head around how to utilize the MVC pattern for a turn based game since it seems like it would split the code up nicely and work really well in a turn based setting.
I have read many articles and posts on MVC architecture, so I understand there is more than one way to set everything up and that it all comes down to needs of the project and what makes it easiest on myself. That being said here are three game themed implementations I have looked at.
Specifically I have really followed Koonsolo's description for the purposes of this question.
I have a simple chess like war game with a scrollable map I built for learning purposes. The model part is very natural, I have entities holding state info like board position and health, a board for the entities to move around on, and some other components like player managers, etc.
The view also seems fairly self explanatory. It holds a reference to the model and uses that to get data it needs to present a visible portion of the board to the user. Right now I am assuming that animation is to be a part of the view as well.
The controller I have implemented as a state machine that pushes and pops controllers based on user input and acts on the model. In the case of A.I., the controller is a single state that analyzes the board currently.
Where I get lost is when
-
I need to have view based input like a mouse click. Say I have a 64 x 64 board and my view only shows 16 x 10. When I click a entity, how should the controller know which piece is selected? Obviously it should query the view, but the view just draws off of the model, so how would I resolve which entity I have clicked?
-
How to actually carry out the animations and where the code for it should go. If I move a piece, attack an enemy piece, and the enemy piece dies, the model updates all of this information at once, so how to I take that scenario and animate it so that the user sees the move, sees the attack and damage happen and lastly the enemy piece die. The first article I linked to just draws strait from the model so entities "teleport" to their final destination and if they die, they just disappear.
-
This relates to part two, but how to handle showing A.I. turns while the A.I. is acting on the model.
Aucun commentaire:
Enregistrer un commentaire