Question

I am working on a Text-Based RPG for Android (just built around the default views and buttons) to get a handle on some things before I launch into a more graphically intensive game. There is a Player who moves around Locations, and each Location has a set of possible Actions. The Locations and Actions have Strings for name and description, which are displayed by textViews.

My question is how to store the multiple Locations and Actions for the game? In its current state, I'm just calling new Location() multiple times in onCreate(), but with the 50 or so I'm planning on, the code would be massive, and I'm sure there's a better way to do it. I've thought about subclassing Location for each specific location, but that would be just as bad. I've also looked at JSON, and using an SQLite Database, and I'm sure there are other valid approaches as well.

Does anyone have any links, or suggesting for storing these "plot" related items?

Was it helpful?

Solution

If I understand correctly, at this time, you have the Location object initialization code - and the required data hard coded - in the onCreate method. This is a fairly good solution for a prototype, but if you want more, you have to outsource the data and lazy-initialize the Location objects when required.

If you are not planning on modifying the Locations, than I would suggest JSON, or even easier: an own text based protocol, that is easy to parse, and store it in files of the assets folder. For example like this:

LOCATION 14 Kitchen LOACTION_DESCRIPTION Entering the kitchen you smell the freshly cut tomatos on the table... ACCESSABLE_LOCATIONS 13 10 24 54 AVAILABLE_ITEMS 56 23 12 8 ...

And you can parse the file line by line with a BufferedReader, building your object.

If locations contain information that may be modified and the modifications should be stored persistently, then you have to use a database. There are lot's of tutorials. This way you can save modifications.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top