Note that there are some explanatory texts on larger screens.

plurals
  1. PODifficulty with implementing MVC design (iOS game)
    text
    copied!<p>I started developing a simple card game iPhone app, but I've been completely stuck for a few days. This is my first program that I will be making outside of CS classes so needless to say it is 20x bigger than anything I've ever done. I have a good idea of basic OO practices and the simpler patterns, but I am struggling in creating a good Model-View-Controller. I could possibly hammer out some procedural and tightly coupled app, but I'd like to use good OO practices. I want to avoid using the Singleton pattern.</p> <p>I understand the big picture, but I get confused when I try to wrap my head around its actual implementation.</p> <p>So far I have (not using the exact APIs atm like UIView):</p> <p><strong>A GameModel class</strong> with instance variables Player *player, Player *dealer, and Deck *gameDeck. Methods are -(void) dealCardtoPlayer, -(Player *) getPlayer(so the view/controller can use reference to get score easily), etc... The Player classes have information like hand and score. This is actually an implementation of a protocol so I can utilize a state pattern if I need to.</p> <p><strong>A GameController class</strong>. Contains references to the GameModel and GameView. That's all I can figure out. If someone clicks on a <em>hit</em> button in the GameView, does that button's method simply call a hitPressed method in the controller which then calls the GameModel method -(void) dealCardtoPlayer:(Card *) topcard? Does the controller constantly poll the model to determine if the player lost or does the model register the controller as an observer and update it?</p> <p><strong>GameView class</strong>. Contains references to the GameModel and GameController(since it sends input to the controller). Does this simply call something like getPlayerHand in the model 60 times/second until it finds a card was added to the hand and then render it ? How would animation be handled? Would the view have its own array of already rendered card elements and transform them(to make room for the new card) once it detects a new card in the player hand and then render the new card? I feel like I should make a state pattern for this too. I think I also read somewhere that animation data is stored in the model, but I'm not sure how.</p> <p><em><strong>Other Random Questions:</em></strong> Does the AI use the same exact controller reference as the player and send its simulated input to the controller? I also want to implement multiplayer later on.</p> <p>I was also wondering how something like a main menu and a pause menu are implemented. Would I use some master controller that controls two MVCs or just switch views in the same GameController? My first guess was the controller would have a menuButtonPressed method that would assign a different view reference (writes over the existing view and gets cleared and deallocated when game is resumed so you see the previous one). If I want to use the same engine to make a side-scroller next how would two controllers work together (I know collision detection usually has its own controller)?</p> <p>I always learn best by example: I've searched Google, but either I'm missing some hidden gems or I can't find the info I need. </p> <p><strong>Primary question:</strong> Are there any must read in-depth tutorials or great books on actually implementing OO/MVC game design?</p> <p>I apologize for the onslaught of long-winded questions, but I really feel like I cannot wrap my head around the intricacies of MVCs. I feel like this app will take months to just get something basic running (it will once classes start again)...</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload