// Decompiled by Jad v1.5.7f. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   TimeCounter.java


class TimeCounter extends Thread
{

    TimeCounter(GameControl gamecontrol, int i, int j)
    {
        keepGoing = true;
        gameLimit = i;
        moveLimit = j;
        gcontrol = gamecontrol;
        gameTime = 0;
        stopped = true;
    }

    synchronized void moveStart()
    {
        startPoint = System.currentTimeMillis();
        stopped = false;
        lastgt = -1;
        lastMoveTime = -1;
    }

    synchronized void moveStop()
    {
        if(!stopped)
        {
            gameTime += (System.currentTimeMillis() - startPoint) / 1000L;
            stopped = true;
        }
    }

    public void run()
    {
        while(keepGoing) 
        {
            synchronized(this)
            {
                if(!stopped)
                {
                    moveTime = (int)((System.currentTimeMillis() - startPoint) / 1000L);
                    int i = gameTime + moveTime;
                    if(moveTime != lastMoveTime)
                    {
                        if(statc != null)
                            statc.timeChange((moveTime * 100) / (moveLimit * 60), moveTime);
                        lastMoveTime = moveTime;
                    }
                    if(i != lastgt)
                    {
                        if(pc != null)
                            pc.setTime(i);
                        lastgt = i;
                    }
                    if(i >= gameLimit * 60)
                    {
                        gameTime = gameTime + moveTime;
                        stopped = true;
                        if(gframe != null)
                            gframe.timeoutGame();
                    } else
                    if(moveTime >= moveLimit * 60)
                    {
                        gameTime = gameTime + moveTime;
                        stopped = true;
                        if(gframe != null)
                            gframe.timeoutMove();
                    }
                }
            }
            try
            {
                Thread.sleep(500L);
            }
            catch(Exception _ex) { }
        }
    }

    void turnOff()
    {
        keepGoing = false;
    }

    static final int DIVBY = 1000;
    GameControl gcontrol;
    boolean keepGoing;
    boolean stopped;
    int gameLimit;
    int moveLimit;
    long startPoint;
    int lastMoveTime;
    int lastgt;
    int moveTime;
    int gameTime;
    StatusComponent statc;
    PlayerComponent pc;
    GameFrame gframe;
}
