package com.backfire.Animation;

import net.yeeyo.doudizhu.feiyu.R;
import android.graphics.Bitmap;

import com.backfire.doudizhu.common.DdzApplication;
import com.backfire.doudizhu.common.PNumber;
import com.backfire.graphics.PCanvas;
import com.backfire.room.data.ConfigCenter;
import com.backfire.room.data.ResCenter;

public class AnimationClock extends Animation{
	public static int ClockTag = 2001;
	private long startTime = 0;
	private int lastTime = 0;
	private int currentTime = 0;
	private long playTime = 6;
	private int x;
	private int y;
	Bitmap clock_bg;
	public AnimationClock(int time,int x,int y){
		this.deleteFlag = false;
		this.tag = ClockTag;
		lastTime = time;
		this.x=x;
		this.y=y;
		startTime = System.currentTimeMillis()/1000;
		clock_bg = DdzApplication.getApplication().getBmpPool().getBitmap(R.drawable.clock, ConfigCenter.clock_bg_W, ConfigCenter.clock_bg_H);
	}
	
	@Override
	public void exec(PCanvas canvas,long sleep) {
		super.exec(canvas,sleep);
		currentTime =(int)(lastTime + startTime - System.currentTimeMillis()/1000);
		if(currentTime<0){
			this.deleteFlag = true;
		}else{
			canvas.drawBitmap(clock_bg, x, y, null);
			int numArry[]=PNumber.getNumEachPost(currentTime);
			int startX=x+(ConfigCenter.clock_bg_W-numArry.length*ConfigCenter.clock_num_W)/2;
			int posY=y+(ConfigCenter.clock_bg_H-ConfigCenter.clock_num_H)/2;
			for(int i=0;i<numArry.length;i++){
				Bitmap bitmap=ResCenter.getClockNumber(numArry[i],ConfigCenter.clock_num_W,ConfigCenter.clock_num_H);
				canvas.drawBitmap(bitmap, startX+i*ConfigCenter.clock_num_W, posY, null);
			}
			if(playTime-currentTime>=1){
				playTime = currentTime;
			}
		}
	}

	@Override
	public void unload() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void overstatue() {
		this.deleteFlag = true;
	}
}
