Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

swiftd

macrumors newbie
Original poster
Jul 12, 2009
11
0
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:
Game
Side
Character

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?
 
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.