Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am writing a game in Objective C/cocos2d where a newspaper is a central part of what controls or rather effects the game's world economy as well as what a city might do (such as increase X, reduce Y)

The newspaper is a bit like a "Chance card" in Monopoly, it has an effect on something.

My question is, what is the best way to do write a newspaper that has both a random and specific effect within the game.

Would the best strategy be to write out all the things a newspaper can affect, a PLIST of headlines (with placeholders).

I think Tiny Tower uses a PLIST of events and it randomly picks an event, but I'm not sure how it actually parses it because certain events do different things.

But then how do I parse all the scenarios that a newspaper can deliver? A big switch statement seems very long and complicated to do.

I am wondering if there is a simpler way to handle this kind of thing.

Related to this is that there might be no news that day and I'm not sure what the newspaper should display, should it just display the last headline?

So, in summary.

1) A newspaper generates a headline, it affects different things, such as the world economy, prices, how city reacts

2) I need the newspaper to generate headlines (although there may be days when there are no headlines at all), but I am not sure how to parse it without using a big-ass switch statement.

Thanks in advance.

share|improve this question
There isn't a best way. You have a lot of design choices available, and the good ones will each leave their own mark on how the game works. It's up to you to pick how they should work in order to make the game work the way you want it to. –  Jonathan Hobbs Oct 11 '12 at 13:31
I agree. Just test, fail, repeat until it sorta works. –  zardon Oct 11 '12 at 15:21
add comment

1 Answer

up vote -1 down vote accepted

In order to "parse it without a big-ass switch statement" you'd use functors AKA function pointers. But since you do not mention which language you are using (PLISTS -> Objective C?) I cannot tell you whether you have those available in your language of choice.

Here is an article on how function pointers work (Objective C).

If you are using a language which does not support function pointers, then you would use the Strategy Pattern instead.

share|improve this answer
All you need is some "type" ID, and a Dictionary associating each type with some method. Now pass all data to that method: result = methodsDictionary[data.type](data);. –  Markus von Broady Oct 11 '12 at 14:28
Sorry, I was not clear about the language, this is my fault. I am using Objective C –  zardon Oct 11 '12 at 15:19
I am playing with a test of PLISTs to hold all my stories for different categories and then use randomization to pick the story, city, product or whatever it is that I am affecting. But I am not sure if this is right, sure its random but it feels wrong somehow –  zardon Oct 11 '12 at 15:21
As @JonathanHobbs said -- how can we possibly know? What does "it feels wrong somehow" mean? You're speaking to industry professionals here, so try to be explicit: We're giving up our time to assist you. Also, "PLIST" is a very specific term and means nothing in the broader scheme; I work with many languages and platforms, but not including Objective C. Do you mean text files? If so, the benefit to loading information in from outside of your codebase is that you need not recompile when you want to change that information. If it's in code, you'll have to recompile each time you change it. –  Nick Wiggill Oct 11 '12 at 17:23
@zardon I've assisted you with that part of your question which was concrete, and thus answerable. You will need to make your own decisions on design. If you want a single, concrete question answered, this is the site for you. Otherwise, a forum is a better choice. –  Nick Wiggill Oct 11 '12 at 17:30
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.