By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,898 Members | 1,183 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,898 IT Pros & Developers. It's quick & easy.

Re: Relationship between GUI and logic?

P: n/a
On May 23, 1:37 pm, John Salerno <johnj...@gmailNOSPAM.comwrote:
Basically, the question is this: can you write the logic behind a
program (whether it be a game, an email client, a text editor, etc.)
without having any idea of how you will implement the GUI?
Hey John,

Are you familiar with the Model-View-Controller pattern? It
specifically addresses this issue, and is very common in game
development.

In your example of a grid-based game like chess, the board & the
pieces would all be defined in the Model. The board may be a 2D array,
so to move a piece, the piece only has to know how to address
locations within the array, or even better, only has to know how to
tell the board where it's moving to, so the pieces don't have to know
how the board is implemented.

The View interprets & displays the Model. You could represent each
square by a bitmap, draw a 3d object, or use ASCII etc etc.

The Controller maps user input to Model behaviour, so pressing 'up'
while a piece is highlighted may call something like
piece.move_north(), which updates the necessary entities in the Model
to reflect the move. It generally also passes information from the
Model to the View, although it's not uncommon for the View to just
refer to the Model separately.

So you can think of the Model as a simulation of the behaviour you
want, while the View is _a_ representation of that simulation. The
simulation doesn't care if you're displaying it in 2D or 3D, it cares
about pieces and board positions. By separating the Model & the View,
you also allow for multiple representations of the same data, such as
having a 2D overhead map and a 3D visualisation of the same
information.

- alex23
Jun 27 '08 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.