Brian A Bird
Brian A Bird

Reputation: 378

MVC -- bridging the gap between my model and its on-screen representation

I am building a Settlers of Catan game in hopes of gaining understanding of proper MVC design patterns.

I have created Core Data entities called Tiles and Corners that represent the game board and each tile has a one-to-many relationship with its (6) corners. These represent my "Model".

I've also created corresponding "View Controller" classes that represent these physical representation of the tiles and corners drawn on screen. I called these Cocos2D classes BoardTiles and BoardCorners.

How do I efficiently explore the relationships I created in the model via the View Controllers?

I've tried:

1) Giving the VC a reference to its corresponding Core Data entity

2) Query the entity's corners (boardTile.tile.corners)

3) Take the resulting CoreData corners and query its VC 'owner' via a unique ID lookup.

Is there a better way to structure this so that the View Controllers have an easier way of accessing the model's relationship data?

Upvotes: 2

Views: 118

Answers (1)

Michael Brown
Michael Brown

Reputation: 498

Games are a very poor way to understand MVC, purely because they tend to have such a small Model domain.

The Model and View are categories/collections/domains of objects. These objects are completely self-contained.

I have created Core Data entities called Tiles and Corners that represent the game board and each tile has a one-to-many relationship with its (6) corners. These represent my "Model".

Tiles and Corners belong in your View domain (Visual objects).

An example that may live in the Model is some form of health system or money system. While your main character has health, he does not (in general) represent this information, You'd have some kind of progress bar or % figure.

the progress bar is a View object, and the stat's relating to the health system is stored in a Model object. Your Health System domain will have rules/policies, and other classes/objects.

Upvotes: 1

Related Questions