Where to save words file for Hangman game on android? - java

I'm trying to make a simple Hangman game for android (without using any libraries like libGdx) and first problem I encountered was this. I don't know where should I put all the words that I made for my game. Should I make it a simple txt file or XML resource file? Should I put that file into new directory or into values directory?
I'll need to read that data file and put all words to String array. File will not be modified during game.
Any advice would be very welcome.

I think it would be best to make use of android's built in sqlite database. If you would use a text file you would have to parse all of the data into an array then pull out a random record to use for your game. If you use a database you are able to pull a random record from the database with a single query. Sqlite would make more efficient use of your resources.

Related

How to include large string array resources in an application?

I am developing a dictionary app where users can download vocabulary through an API. But I don't want to make my app look empty until they searched for their first word. So I have managed to arrange all the words with their definitions as string array and thought of displaying them as a list.
The problem here is that as I stored vocabulary with their definitions the string array gets too long that the android studio wont allow me to store such a huge number of vocabulary items in the resource array. Also by doing so the app size might increase a lot. I saw many offline dictionaries that work without downloading data on their first run. How did they achieve that ?
Any idea is appreciated. Thank you
You should create and Offline database like the SQlite database. Storing Big amounts of data in the string array is not an efficient way here.
This link may help you.
Or you can search for other offline databases.
For offline dictionary, you can store data into CSV file then import CSV file into your android studio project, either you can directly read content from it or you can insert into sqlite.

Can I save a text file without giving users ability to modify it?

I'm working on a game and I am at that part that I want to save the game progress into a text file (or maybe a properties file would be good too), but I'd like to save that file to a place that is not reachable for the players. I was thinking about saving it to a source folder inside the program, but I am not able to save or load a text file from there, only images. Could anybody suggest something how/where to save the game stats that players can not just go into the settings file and modify their score or level or something like that?
With the properties file my only problem is the saving, where I need an output stream or a writer to save it, what I', not able to get
Assuming your player's pc has a regular hard drive with regular standards then:
If the game is offline(and maybe later synced with a server) then the answer is NO; if your app can access the file so does the user; even if you encrypt the data written to the save file people can just reverse engineer your app and get the keys and algorithms and modify the file; to put it simply you can only complicate it, their access to save files is inevitable.
If your game is only possible to be played online then you can do sanity check for every action of the players and save the progress in an inaccessible by players manner;
About the read only, been asked before:
create a read-only file
For the second one, keep in mind that as you know the path to the file and the name of it, the user don't. Saving the file using "scary" name, in un-trivial path will protect the file from any changes for a while

How should I save a dictionary database with java?

When I google "how to make a dictionary", it gives me a great measure of the explanation of "make", which is very helpful. But I need something else, so I put this question here.
I want to make a small project. I want to make a dictionary with java or android. But I don't know how should I organize the words. I have considered a JSON file, a XML file or I can also simply output all the words as ojbects into a file. Could anyone please give me some adivce?
Assuming that you want to be able to read (quickly) values from your dictionary, and maybe update values or create new values then I suggest that you store your dictionary in a Database. For a simple Java database I suggest that you use an embedded Derby Database.
see http://db.apache.org/derby/

Organizing data in java (on a mac)

I'm writing a tool to analyze stock market data. For this I download data and then save all the data corresponding to a stock as a double[][] 20*100000 array in a data.bin on my hd, I know I should put it in some database but this is simply performance wise the best method.
Now here is my problem: I need to do updates and search on the data:
Updates: I have to append new data to the end of the array as time progresses.
Search: I want to iterate over different data files to find a minimum or calculate moving averages etc.
I could do both of them by reading the whole file in and update it writing or do search in a specific area... but this is somewhat overkill since I don't need the whole data.
So my question is: Is there a library (in Java) or something similar to open/read/change parts of the binary file without having to open the whole file? Or searching through the file starting at a specific point?
RandomAccessFile allows seeking into particular position in a file and updating parts of the file or adding new data to the end without rewriting everything. See the tutorial here: http://docs.oracle.com/javase/tutorial/essential/io/rafs.html
You could try looking at Random Access Files:
Tutorial: http://docs.oracle.com/javase/tutorial/essential/io/rafs.html
API: http://docs.oracle.com/javase/6/docs/api/java/io/RandomAccessFile.html
... but you will still need to figure out the exact positions you want to read in a binary file.
You might want to consider moving to a database, maybe a small embedded one like H2 (http://www.h2database.com)

Any existing java library to delete , edit , add certain line in a file with swing in Jmenu?

I am now using Fileutils to access a file to retrieve lines of phone number.
But now I need to add phone number , delete phone number and edit phone number in the file. I do know how to do it with JMenu , but i keep wondering , do anyone create a library for this?
I would suggest you to go for DB .
FILE IO in such case is very ugly coding.
and then also if you want to do it.
to modify content you need to create other file read from older and modify it in memory and write it back to new file.
If you don't want to go for DB, which is the best idea, you should maybe.
Read the whole file and store in a Collection
then, you remove the phone number, and then write it again on file overwriting.
It's definitely much more work. But it works too.
Reminding that the class of the ObjectType needs to implements Serializible.

Categories