I am programming a Text based RPG game for Android in order to familiarize myself with Java and XML. I want to display a string array of choices across a ListView of buttons, and depending on which button the user presses, I want to update the activity accordingly with a new set of choices.
For example, lets say the game starts off with the following choices:
{option1, option2, option3, option4}
If the user clicks on option2 i want to display:
{2-option1, 2-option2, 2-option3, 2-option4}
or lets say the user clicked on 4 instead of 2. Then:
{4-option1, 4-option2, 4-option3, 4-option4}
So, i am trying to determine a speed efficient / memory efficient way of determining the next String[] to display.
Originally i was thinking about constructing a GIANT if-then-else tree (or switch statement - doesn't matter), where there would be an if statement for each possible option. For example:
//choice is the user selected option
if(choice==option1){
return {"1-option1", "1-option2", "1-option3"}
}else if(choice== 1-option1 ){
return {"1-1-option1","1-1-option2","1-1-option3"}
And the List would go on and on until every possible choice returns a String[] that corresponds to the next group of options that are to be displayed.
Then, i started thinking maybe it would be cleaner and easier to do this with objects:
MyObject newObject = MyObject(choice)
newObject.getOptions()
where choice is a constructor parameter that initializes a String[] to the proper next set of options; and getOptions() returns this String[]
However, this is going to be a lot of objects, and i am not sure it will simplify things over the if/switch statement method.
So, any ideas of an efficient way to handle something like this?
Aucun commentaire:
Enregistrer un commentaire