I have a bit of a rookie question regarding storage of map data i a java game. I'm making a 2d tile-based game, where each tile has an id (1, 2, 3, 4 and so on...). I currently store the game data in a .txt file, where each number is seperated by a tab. Therefrom i read it via scanners .nextInt.
This method works fine, but it seems to give me a problem:
Since the level file is just a normal .txt file it is easily edited by anyone. This means that the user could just change a few numbers in the file with any kind of text editor and thereby easily cheat.
How would this be avoided? Should i store the map data differently or should i use some form of encryption?
One solution to this would be to store the data in a database, such as derby. Once the game has been exported as a jar file the casual player will never even see the file, and if they do get their hands on it, probably wouldn't know what to do with it.
Here is a nice tutorial on how to set up and connect to a simple derby database.
http://www.vogella.com/tutorials/ApacheDerby/article.html
good luck.
Java has a Serializable interface that can be used to save java objects.
API docs can be found here: http://docs.oracle.com/javase/7/docs/api/java/io/Serializable.html
This doesn't make it impossible for people to cheat and change the maps just more difficult.
If you're really worried about it you could use some form of encryption or add a checksum to further prevent tampering.
Related
I am coding a questionbank with netbeans as a school project. I am using a JFrame GUI to enter question data. I need some clever way to store, edit and delete data in some file. I donĀ“t want to use any databases. I already tried solving this with txt files but it is tedious and wont work. I need some option where I can add an entire question to the file and then when I retrieve it retrieve certain parts. The data below is how I tried solving it. I then used a scanner to read the files line by line and stop everytime a "_" is read. Is there any better way to store this. Or can i store this in a 2 dimensional array in the java program itself.If so any help or solution is appreciated
Geography_What is England's capital_Berlin_Manchester_Dover_London_D_3
Maths_What is 2+3_7_9_5_6_C_1
Economics_What is demand_idk_stuff_demand_supply_C_2
Well, if you dont want databases or any external files, the only way to "store" information is to create some data structures to do so. The issue with that is they wont persist past the lifetime of the current running application.
Id advise to use some form of external file, or set up a simple sql db. Its easy and will make the project simpler
I plan on reading several files when my app/game is created and using the information from them for the entirety of the app. I also have to write to the file at one point.
I have two files. One is a 2-column text file that I'll turn into a dictionary for fast searching. The other is a text file that has 11 columns. I'll make a dictionary out of two of the columns, and the other data I need kept as is so I can write to the columns to count the amount of times something happens in different circumstances for datamining.
Currently, I've turned the second file into a list of a list of strings, or List>. I can't figure out how to pass that around in intents. ".putStringArrayListExtra" only works for a list of strings.
Am I going about this the wrong way entirely? This is my first real Android app.
In order to store a data structure into an Intent, it has to be either serializable or parcelable. If your data structure is neither of them, you might create a class that would implement Serializable and manage it. A good example might be found here.
Once done, you then might use Intent.putSerializable(...) to store your data structure. See this:
Using putSerializable in Android
Additionally to this, if you could convert your structure into a JSON structure, you'd already have it done since it would be treated as a String. If not, the above solution should be easy to do.
I've made an Android application which contains most used German words and sentences. The application contains a CSV file which stores all the data.
Currently it is working as expected but I want to ask if there is a better way to store such data directly in the app?
I'm also thinking about the ability to update the data via internet like adding new words and sentences.
Thanks!
Miretz
If you want to modify the content (update, remove etc.) I would suggest using SQLite DB which has a pretty nice built-in integration with the Android platform.
There are 2 types SQLDatabaseLite and SharedPreference. Major difference between both is that one is organized and the other not so.
If you need a quick use of a storage facility within your app for example changing text sizes between activity SharedPrefference works best for you.
If you have a complex database system where you need more than one data to be saved for a particular event SQLDatabaseLite is for you example of this is spreadsheet of data for customers; Name, Phone Number, etc.
I am working on a project here that ingests internal resumes from people at my company, strips out the skills and relevant content from them and stores it in a database. This was all done using docx4j and Grails. This required the resumes to first be submitted via a template that formatted everything just right so that the ingest tool knew what to look for to strip the data.
The 2nd portion of this, is what if we want to get out a "reduced" resume from the database. In other words, I want to search the uploaded content I now have, and only print out new resumes for people who have Java programming experience lets say. So I can go into my database, find the people who originally had java as a skill, and output a new set of resumes that are also still in a nice templated format, and only have the relevant info in them, instead of ALL the content.
I have been writing some software to do this in Java that will basically use a docx template, overwriting the items in customXML which are bound to the content controls in the doc, so the new data shows up and can eb saved as a new docx with that custom data.
This seems really cumbersome to me, and has some limitations. For one, lets say my template has a place for 3 Skills, and the particular person has 8 skills. There seems to be no good way to add those 5 additional skills to the docx other than painstakingly inserting the data with all of the formatting XML tags and such. This is a real pain, because if the template changes, I dont want to have to go back into my software and edit source code to change that additional data input XML tag to bold instead of italic.
I was doing some reading up on using Infopath to create a form that I could use to get the input, connecting to some sharepoint data source or something to store the stripped out data. However, I can't seem to find out if it is possible using sharepoint to get the data back out, in a nice formatted way. What would the general steps for this be? It seems like I couldnt find very much about this topic with any quick googling.
Thanks
You could set up the skills:
<skills>
<skill>..</skill>
<skill>..</skill>
and use a "repeat" content control pointing to the container. This would handle any number of <skill> entries.
I'm making a game in Java, and I need a good file format to store the player's saved data.
Any suggestions?
Feel free to give examples in code if you want.
EDIT: This is a server-client game, so the saved data will be on the server's machine. Also, I don't want to use Serialization.
XML
let's you save any data structure you may have in a standard format and you won't need to write your own parser/writer for it
if you need the files to be "secured" from gamers changing their scores/progress/... (not sure where the files are stored? or whether this matters?) you could pass the XML through an encryption algorithm or encrypt the data elements before putting them into the XML
All of the answers so far seem to be about XML, which isn't a bad format, but there are other options you might find useful, which should make your startup times faster:
Json: Common and has been around longer than my next two suggestions.
Thrift: What Facebook uses. Should be faster than Json, supported by less languages.
Protocol Buffers: Used by Google. Probably the fastest, and also easy to extend.
Or just make your classes support Serializable.
If as you say, the information will be saved on the server it should definitely be in a database. The typical game protocol is store the user information in a database - pull it into memory when they login, with lazy updates to the db for changes to the object in memory (keeps game performance high) as they play the game and update their "in memory" user game state object.
Don't limit the scalability of your game by starting with file based storage just because it might be slightly easier.
Since its your game, you could define a file format yourself. For saving game's state directly serializing and storing will do. As for the players saved data (which could be his level progress, game score etc) you could use XML.
<?xml version="1.0"?>
<Game>
<player id="01d">
<name>
John
</name>
<skill>
Rookie
</skill>
<score>
122
</score>
</player>
</Game>
Ofcourse you could encrypt it to make it hack-proof