开发者

confused with MVC in Objective C

I have a small slots game almost developed for iPad as this is my very first interaction with any of Apple technology, so I never really designed this application properly while developing, I want to mould this code into, what apple advocates, Model-View-Controller style. I read a lot about it but still confused. This is what I have:

  1. ViewController class created by default
  2. Some methods to control the animation
  3. Textiles for some data and some methods to access them
  4. Methods to calculate payouts and winning amounts

So what s开发者_如何学JAVAhould I exactly do now to convert it into MVC, how should my approach be? Also tell me any good books or online documentation for the same

Thanks in advance!!


The model should represent the state of your game at any time, but not in a visual sense. Think of it as the game logic. So it would have current score, current state of slot reels etc. The model would also be responsible for "spinning the reels"

The view is a visual representation of that model, you can render that information in any way you like, 3D, 2D etc and it makes no difference, the model is the same (this is the real benefit to MVC).

Your controller (commonly a Viewcontroller in iOS) mediates between the model and controller - it should take input from the user and respond to changes in the model, updating both the model and view as required.

The reason for the three way split is that you can change just one of the MVC elements and have the app continue to work. You could change the model to spin the reels in a better way (more random) you could change the view from 2D to 3D (or iPhone to Mac) and you could change the event handling in the controller (e.g. add shake to trigger a spin). All independently.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜