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'm trying to figure out the best design here, and I can see multiple approaches, but none that seems "right."

There are three relevant classes here: Base, TradingPost, and Resource. Each Base has a TradingPost which can offer various Resources depending on the Base's tech level.

Where is the right place to store the minimum tech level a base must possess to offer any given resource? A database seems like overkill. Putting it in each subclass of Resource seems wrong--that's not an intrinsic property of the Resource. Do I have a mediating class, and if so, how does it work? It's important that I not be duplicating code; that I have one place where I set the required tech level for a given item. Essentially, where does this data belong?

P.S. Feel free to change the title; I struggled to come up with one that fits.

share|improve this question
1  
It sounds like you can just keep this as an attribute of the base: a list of resources, and a correlating list of the minimal base level before that resource appears. –  ashes999 Jan 3 '13 at 16:20
add comment

1 Answer

up vote 1 down vote accepted

IMHO, the responsibility of managing which Resources are available in a TradingPost should be in a separate controller-like class, TradingPostController for example.

TradingPostController observes changes of Base.techLevel and updates the TradingPost's set of offered Resources accordingly. In this approach, TradingPostController will contain a mapping of tech level -> resource set.

So the sequence of events would be:

  • Tech-level of Base is increased.
  • Base fires a "tech level changed" event.
  • TradingPostController observes the event.
  • TradingPostController updates TradingPost.resources (or so).

Good luck!

share|improve this answer
add comment

Your Answer

 
discard

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.