package app.mar.game;

import android.util.Log;

import com.google.zxing.common.StringUtils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;

public class Bomb implements Serializable{
    protected long      mDeadLine;
    protected String   mPassword;
    protected char    mPasswordKnown[];

    public Bomb(String pwd, int min)
    {
        mPassword=pwd;
        mPasswordKnown=new char[mPassword.length()];
        for(int i=0; i<mPassword.length(); i++)
            mPasswordKnown[i]='_';
        mDeadLine = Calendar.getInstance().getTimeInMillis()+min*60*1000;
    }

    public void addKnownCharacter(int pos, char c)
    {
        mPasswordKnown[pos]=c;
    }

    public String getPasswordKnown()
    {
        String s = "";
        for(int i=0; i<mPassword.length(); i++)
        {
            if(i>=0) s+=" ";
            s+=mPasswordKnown[i];
        }
        return s;
    }

    public void addTime(int minutes)
    {
        mDeadLine+=minutes*60*1000;
    }

    public String getTimeBeforeBoom()
    {
        long now = (mDeadLine - Calendar.getInstance().getTimeInMillis())/1000;
        int h=0,m=0,s=0;
        String ret = "";

        s=(int)now%60;
        m=(int) (now%3600)/60;
        h=(int) now/3600;

        if(h>0)
        {
            if(h<10) ret+="0";
            ret+=h;
            ret+=" : ";
        }

        if(m<10) ret+="0";
        ret+=m;

        ret+=" : ";

        if(s<10) ret+="0";
        ret+=s;

        return ret;
    }

    public boolean hasExplosed()
    {
        return mDeadLine < Calendar.getInstance().getTimeInMillis();
    }
}
