Hey, I'm implementing a simple Breakout clone in Java and try to make it conform to the MVC pattern. I confess, I come from a web background and have used MVC only in the Php framework Symfony, never in a desktop application. So my problem is to decide which entity is responsible for which tasks.
I divided my project into those classes:
Breakout extends JFrame(main class) initiates theMainViewControllerand adds its view to the content pane.MainViewController extends TimerTaskinitiates theMainViewand handles its mouse and keyboard events. Also runs the game loop (calculates the position and state of the game objects, i.e.Ball,Paddle,Bricks), is that right in this place?MainView extends JPanelsimply drawsBall,Paddle,Bricks on the screen, no logic in here. But, it also initiates those objects. I'm afraid, this isn't correct, right?
Finally the game elements:
Ball extends Ellipse2D,Paddle extends Rectangle2DandBrick extends Rectangle2Doffer methods to move them on screen, but also collision detection is done here. Again, I doubt this is the right place, move it to the controller?
And what is the model? I guess, exactly those game elements because they represent the only data that is changed during the game. But those are controller elements since they offer collision detection logic, too. And the best thing about them is, they are initiated in the view class. I'm sure, something went wrong in my design decision.