Regarding how to implement a game with MVC

Discussion in 'iOS Programming' started by swiftd, Jul 24, 2009.

  1. swiftd macrumors newbie

    Jul 12, 2009
    Hey guys, I'm new to both iPhone programming and programming in general and have a question. I'm making a tile-based game, and I'm not sure if I'm going about it the right way. Please note at the moment I am just putting the game in the initial ViewController for ease, I will worry about menus etc later.

    I have the following classes:

    I create a Game instance, which creates two Side instances, which each create 3 Character instances.

    Now the way I'm doing this is the ViewController viewDidLoad method, passing down the self parameter as I create the classes so that when I eventually get down to the character setup I can call a method in ViewController to place the characters on the tiles. Is this correct? Or should I have my classes set as global variables so that I don't have to do this?
  2. firewood macrumors 604

    Jul 29, 2003
    Silicon Valley
    Sound like a good case for MVC. There seems like there can be a lot of actors and the state can quickly become complicated/convoluted. Put all your game state in the model, and your game will be more future proof and expandable.

    There are interesting variations. You can have the game controller figure out where all the players are and send the positions down to the view. Or you can have the game controller ask the characters to draw themselves, and give the characters access to their own view update methods. Etc.

Share This Page