Pergunta

I'm actually really new to java. I've noticed a lot of people take on a similar task, but I can't seem to find the answer I think I'm looking for. I'm making a very simple Pokemon game (learning purposes). Long story short, my question is about handling the abundant amount of creatures/characte0rs/objects(?) that need to be created.

The technique I've been using is with a pokemon superclass with setters and getters. Was wondering about xml files to store the list of 150 different pokemon (each with different attribute values, but all with the same set of attributes). But it seems like that involves a lot of coding as well. I like that I can also create a class to read and write the xml file, to recieve data and potentially create/change data as well.

BUT, I've seen use of a list-like sheet that basically looks something like:

Pikachu,12,30,20,15,Thunder Bolt,Quick Attack,electric,none,etc...

Bulbasaur, 20,52,16,Leech Seed,Growl,plant,fire,etc...

(name,atk,def,speed,move1,move2,type,weakness,etc...)

Where the different attributes of the object(pokemon) are stored in a line seperated by commas. If i understand correctly, these attributes are then read by a method that needs very little coding to read the whole line, and then plugs in the values on the line to their proper variable in the object without having to restate the name of each variable.

Im a complete java noob, sorry if this is completly wrong. Im really just curious what this technique is called and where i can find resources for learning it. If it's even a viable option for what im doing. Also curious if this technique(datasheet?) is capable of being edited by java like xml is.

Any help would be greatly appreciated.

Foi útil?

Solução

What you are referring to is a csv file which stand for comma separated value. There are many existing methods for reading and writing these files in just about any programming language, including Java. csv is a very common structure for storing data that is in a table format, meaning there are rows and columns. Generally, each row represents a record, or object in your case, and is expected to have the same number of fields, or attributes in your case. The first line typically states the field names, but sometimes this provided separately.

xml allows for hierarchical data. Maybe you don't know how many moves each pokemon will have, some might have 1 and others could have as many as 5 for example. xml might be a better choice in this case.

I recommend implementing both if you can to see which one works better as a learning experience. Also, this sounds like a great opportunity to learn about polymorphism. Check out this Java tutorial on it.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top