I have a game where the user is moving around on a canvas and can interact with an item in this scenario a dog which triggers a battle.
This loads up a dialog giving the user the option to fight or run away. The user clicks fight, which then brings up another dialog, this displays some text (your details and the dogs details), and underneath that text there is an attack buttons.
When you click the attach button a few things happen (not relvent), which essentially mean the user and dog details change (e.g. DogHP drops to 18).
So my question is:
- The first dialog box that I load has dynamic information ‘Dog HP’.
- After the attack button is clicked then that information is changed.
- Therefore, I need to update the first dialog box with the new information which I am currently displaying using builder.setMessage()
- e.g. orginal HP = 20 … attack button clicked … new HP = 10
Please see some code snippet below, any ideas or guidence would be much appreciated:
Code Snippet:
void Fight()
{
final int DogHP = 25;
final int DogAtk = 15;
final int DogDef = 5;
final int DogSpeed = 20;
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(context.getText(R.string.monster_dog_title));
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.fight, null);
builder.setView(view);
final AlertDialog DogBattle = builder.create();
View FightBtn = view.findViewById(R.id.dog_fight);
FightBtn.setOnClickListener(new OnClickListener()
{
boolean attacked = false;
@Override
public void onClick(View clicked)
{
if(clicked.getId() == R.id.dog_fight)
{
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(context.getText(R.string.monster_fight));
builder.setMessage("Your Current Battle Details:\n" + "HP = " + UserHP + " Def = " + UserDef + " Atk = " + UserAtk + "\n\n" + "Your Enemy:\n" + "HP = " + DogHP + " Def = " + DogDef + " Atk = " + DogAtk);
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.monsterbattle, null);
builder.setView(view);
final AlertDialog BattleRun = builder.create();
BattleRun.show();
View LeaveBattle = view.findViewById(R.id.Attack);
LeaveBattle.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View clicked)
{
if(clicked.getId() == R.id.Attack)
{
// SOME CODE GOES HERE
}
}
});
}
}
});
}
Thanks in Advance for any help.
I decided to completly scrap the idea above, as it was too much happening in the dialog and ended up creating a new class along with using objects instead of variables.