0

I'm making an Android App for my friends and family based on the game Taboo. Basically, the game displays a main word, and then a list of restricted words. The object is to get your teammates to say the main word, but you cannot say any of the restricted words.

For this app, I would need several hundred main words, plus 7 restricted words for each main word.

My issue is how to store these so they can be accessed by a randomly by the app.

My initial thought was to use an XML resource using string arrays, but I do not know how I would reference these with a random generator.

I am open to any and all suggestions. I am working in Eclipse using the Android SDK.

Just to clarify, I am experienced in Java/C/C++, but this is my first Android App. I have the game framework almost complete, and this is my only major issue.

Any help is appreciated.

BlackBelt2025
  • 441
  • 1
  • 7
  • 18

3 Answers3

0

You can use the xml method you said with a random. Something like this:

Lets say you have 1 string-array which contains the 8 words (1 correct and 7 restricted), you can have as many arrays with different names. They are saved in string.xml

Now in java create the Random and check what number you get, then if you get x number open x string-array.

Here's an example:

<string-array name="a">
    <item>A</item>
    <item>B</item>
    <item>C</item>
    <item>D</item>
    <item>E</item>
    <item>F</item>
    <item>G</item>
    <item>H</item>
</string-array>

now in java:

Random r = new Random();
int i1 = r.nextInt(max - min + 1) + min;

then check your number:

if (i1 == 0){
//do your magic code here with string-array a
} else ...

or use any method you like, like switch...

Edit: or a trick can be to make names of string-array a# (Of curse # is a number) then do:

array = getResources().getStringArray(R.array.a+i1);

With this method you don't need the if else or switch or whatever you want to use.

NOTE: this code is from my mind so it can have some writing errors.

Rotary Heart
  • 1,899
  • 3
  • 29
  • 44
0

It seems like you have a data model as such: you have a list of main words. Each main word object contains the word itself and then a list of associated restricted words.

This looks like something you can either do with JSON or XML (or Protocol Buffers, I guess). I'd go with JSON because it has a balance between speed and Android support. You can create the JSON files using an editor, and they can look like this:

[{
    "name": "animal",
    "restricted": ["cat", "dog", "mouse"]
},{
    "name": "fruit",
    "restricted": ["kiwi", "apple", "orange"]
},
{
    "name": "city",
    "restricted": ["Paris", "London", "Madrid"]
}]

Once you open the file and convert it to a String, you can parse it using JSONArray(yourString) and then use the appropriate methods from there to get each individual word JSONObject, its name String and its JSONArray of restricted word Strings.

Oleg Vaskevich
  • 12,444
  • 6
  • 63
  • 80
0

I developed a quiz app (one question, multiple choice of 5 answers) in which I stored everything in a SQLite database. With this implementation you could also use categories for your words if you wish to. What you can do is get a count of how many words there are and have this as an integer arraylist containing 0 to however many. Then I shuffled the list so it's in a random order. This way I don't repeat any question, unlike when using random which potentially could. Another possibility is to remove the word each time you use it if you do wish to use random. The benefit of this way is also that you don't have to reference each string, string array etc - you could just add more words each time to the database and the fixed structure will deal with it automatically.

AndroidPenguin
  • 3,445
  • 2
  • 21
  • 42