0

My project is to create a flip card game in Android like http://partyhatmy.blogspot.kr/2012/08/angry-bird-matching-card-game.html. The differences are that there will be 3 x 4 total 12 cards on the screen, and the game will have a timer. So if the timer expires or if the user finds all pairs, the new stage begins.

My problem is that I do know how to implement this using SurfaceView, but since all cards are at fixed positions, I think it might be possible to implement the game using layouts in xml, but I don't know how. Is there any starting point resource available on the web?


Edition 1

My Code is like this: I just first want to print the remaining time to one TextView to the screen. The problem is that the screen is all black (without runOnUiThread() invocation, the activity draws the given layout activity_game flawlessly.

public class GameActivity extends Activity {

private TextView mTimerTextView;
private int mRemainingTime = 30;

@Override
protected void onCreate(Bundled savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.activity_game);

    mTimerTextView = (TextView)findViewById(R.id.remaining_time);
    this.runOnUiThread(new Runnable() {
        public void run() {
            long lastSystemTime = 0;
            mTimeTextView.setText(String.valueOf(mRemainingTime));
            while (mRemainingTime > 0) {
                if (lastSystemTime == 0) { // initial run
                    lastSystemTime = System.currentTimeMillis();
                    continue;
                }

                long currentTime = System.currentTimeMillis();
                long elapsedTime = currentTime - lastSystemTime;
                lastSystemTime = currentTime;

                if (elapsedTime > 1000) {
                    mRemainingTime--;
                    mTimeTextView.setText(String.valueOf(mRemainingTime));
                }

                // To avoid excessive loop
                try {
                    Thread.sleep(100);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    });
}

}

1 Answers1

0

see this link it will help you with flip animation

Displaying card flip animation on old android

or

http://www.techrepublic.com/blog/software-engineer/use-androids-scale-animation-to-simulate-a-3d-flip/

use this coode to do changes in ui thread

 MainActivity.this.runOnUiThread(new Runnable() {

    public void run() {
       //do ui changes here

    }
});
Community
  • 1
  • 1
Meenal
  • 2,879
  • 5
  • 19
  • 43
  • Thank you very much. But is it possible for another thread to manipulate the ImageView objects dynamically? For example, I want to have a timer and if the timer is about to expire (say 5 seconds), I want to add a red blink animation on the remaining cards. Your link only shows how to handle flip using onClickListener – user3165752 Jun 03 '14 at 06:12
  • Great! Do you know when to put runOnUiThread() inside MainActivity? I first put it right after setContentView() in onCreate() method of the MainActivity, and the program seems not running fine..... – user3165752 Jun 03 '14 at 06:59
  • put this in your timer class...not in oncreate..or can you post your code..so that i can say excalty where you have to add it – Meenal Jun 03 '14 at 07:24