Sign in to follow this  
Youngee0

[java] ^_^about MVC & J2me^_^

Recommended Posts

Usually,when we would like to code a new game for mobile by j2me,and if we have to switch among different scence frequently,it's recommanded that use a MVC to design while coding. MVC is short of Model-Viewer-Control.It's said that Model contains all structres,and so on. Would you pls give an example explain how to do it? Take Gobang for an example.Assumed that you are going to code a gobang game.And then what would you design?Tks for your kind help.

Share this post


Link to post
Share on other sites
The model would be the in-memory representation of the board: a grid of tiles that may contain a piece of either color. It would also provide functions to determine whether the game is over or not, who the active player is, and to change the state of the board by making a valid play.

The view would be the on-screen representation of the board: it would allow specifying the list of displayed pieces (and their colors), the color of the active player, draw them and then report if the mouse was clicked anywhere on the board.

The controller would connect the model and the view: it would wait for the view to report that the mouse was clicked, determine what tile was clicked on, and tell the model to make a play there (or report that it's invalid). Then, it would rip the data out of the model and specify to the view what should be rendered.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this