Jump to content
  • Advertisement
Sign in to follow this  
dxFoo

OO game question

This topic is 4840 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Since this is my first real OO text-based game, I thought I'd ask about something. Each map has a grid of 10x10, such as A3, C4, etc. Should each city have methods of these areas? For example, If the player is in A1(), and moves east, it'd just pass his object reference to A2(). That would be 100 methods just for the map itself if I went this way. To me, this seems to be the most managable way. Is there a preferred way?

Share this post


Link to post
Share on other sites
Advertisement
Each cell in the map is data. You could create Cell object which you instantiate once per cell, giving it the specific data for the cell (such as connectivity, etc). The cell object probably also knows about the owning "map" object for higher-level stuff.

Share this post


Link to post
Share on other sites
100 of anything is unmanagable. Maybe you should have a 2d array of tiles or grid pieces, with x and y locations, and maybe a "listener" (so to speak) which is basically an implementation of a "action" interface, which you can add to each piece, which will allow you to code whatever you want for any number of pieces, instead of having 100 functions you have to implement. Either way, you may want to redesign your project if you are coming up to this problem.

Share this post


Link to post
Share on other sites
Thanks for the responses. I have my maps drawn out in grid that's 10x10 already. I pretty much look at this when I need to. I'll try that out, hplus0603.

Share this post


Link to post
Share on other sites
All the map locations should probably behave in more or less the "same way", except for minor differences that could be controlled by data. Polymorphism - setting up several classes that are substitutable for each other - is only appropriate when there's some fundamental difference in how the behaviour has to work.

So yeah, what you'd normally do is make a single class Cell, which represents "a spot on the map". The Map then contains an array of Cell objects, and some indication (could be a Cell*, or just an int which is an array index) of which one contains the player. When the player does something, you can tell the Map about it:

- If the player wants to move, then change the "current Cell" indicator.
- Otherwise, call the appropriate function, on the current Cell.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!