Jump to content
  • Advertisement
Sign in to follow this  

Basic game - class design question

This topic is 3403 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

Hey guys! I just have a general question. I'm not particularly new to programming, though I'm still learning a lot and don't know too much about more advanced material like data structures beyond arrays and arraylists. However, I am a newbie when it comes to game programming and the logic behind it. I'm just playing around with some code in java (my AP comp sci class uses it) and I was making a simple text-based game. For the game, I have my main game class and a room class. In the main class, I use an arraylist to store all the room objects. The room objects get created when a player first enters the room, which doesn't sound right to me. So my question is this: what is a more efficient way of managing all the room objects? Thanks for all the help! -Alex

Share this post


Link to post
Share on other sites
Advertisement
Is this a loading time problem? Load all the rooms in advance when you start the game. If you have too many rooms, then load all the nearby rooms in a separate thread so they're ready when the player finally gets to visit them. Also try to reduce the time required to load a new room.

If you have less than a few thousand rooms, then there will be basically no difference between the various methods of handling the rooms, so the easiest method wins.

If you have more than a few thousand rooms, I suspect that they will be proceduraly generated instead of being designed in advance. In that case, you can unload them as soon as the player gets far enough from them, and only store in memory whatever the player did within the room. This way, the amount of memory used by the system is determined by the number of important player actions, not by the number of visited rooms. And you can save those actions to file after a while.

Share this post


Link to post
Share on other sites
No, this isn't a loading time problem, I just wasn't sure how best to do this. So with what you said, having a load() method right at the beginning of the program and just creating all the room objects there would be fine? This way I don't even need an arraylist since there is a fixed room amount and there would be no reason to procedurally create them.

So for example I have my game class:

public class Game {


public static void main(String[] args) {
Display main = new Display();
}

}


My display class:

public class Display {

public Display() {
load();
}

public static void load() {
Room one = new Room();
}

}



And my room class:

public class Room {

private static int idCounter = 1;
private int id;

public Room() {
id = idCounter;
idCounter++;
}

public int getID() {
return id;
}

}


Is this the proper way to go about managing the rooms and loading?

Thanks for the reply!
-Alex

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!