-1

Sorry if iam not able to give accurate title to my question Iam Working on an android game in which i have a fuel bar i.e 10 random vertical lines make a fuel bar in my game case. When a player taps on rematch,the game then One fuel bar became gone i.e 9 left. Same way if rematch happen 10 times then fuel bar is empty Now what i need to do is IF a player rematch the game 5 times then fuel bar would be 5 and if he close the app, comes back after 5 minutes again then the fuel bar should be again 10. i.e I wanted to increase one fuel bar after every minute. What exactly i have to do keeping in view that shared preference will also be used. Any link or example would mean alot to me

Here is my onclick for rematch button

    if(fuelcount==9)
    {
        lifefuel.setImageResource(R.drawable.batterynine);
    }
    else if(fuelcount==8)
    {
        lifefuel.setImageResource(R.drawable.batteryeight);
    }
    else if(fuelcount==7)
    {
        lifefuel.setImageResource(R.drawable.batteryseven);
    }
    else if(fuelcount==6)
    {
        lifefuel.setImageResource(R.drawable.batterysix);
    }
    else if(fuelcount==5)
    {
        lifefuel.setImageResource(R.drawable.batteryfive);
    }
    else if(fuelcount==4)
    {
        lifefuel.setImageResource(R.drawable.batteryfour);
    }
    else if(fuelcount==3)
    {
        lifefuel.setImageResource(R.drawable.batterythree);
    }
    else if(fuelcount==2)
    {
        lifefuel.setImageResource(R.drawable.batterytwo);
    }
    else if(fuelcount==1)
    {
        lifefuel.setImageResource(R.drawable.batteryone);
    }
Arslan Ali
  • 371
  • 5
  • 20

1 Answers1

0

As you said, you could use the shared preferences to store the the time of the last fuel bar change.

Also, you should read about the Android lifecycle, and understand how to use methods such as "onPause", "onResume", etc.. http://developer.android.com/training/basics/activity-lifecycle/pausing.html

In the end, the goal is to have your application recalculate the fuel-bar every time it is continued.

DougieHauser
  • 460
  • 6
  • 14
  • Sir can you help me in another problem? Iam a beginner here and stack overflow doesnot allow me to ask another question – Arslan Ali Feb 20 '16 at 14:36
  • Sorry sir for late question I want to generate random tic and cross images for tic tac toe game – Arslan Ali Feb 24 '16 at 11:59
  • the problem is that tick and cross random images are generated on tic tac toe board but when i tap on next move then the color of previously tapped tic/cross also changes. – Arslan Ali Feb 24 '16 at 12:00
  • Are you sure you can't open this in a new question? I mean, time DID pass... If you could post some of your code that would be very helpful as well. – DougieHauser Feb 25 '16 at 14:45