Example #1
0
        // Does the work of updating timer
        internal void DoCountDown()
        {
            mTimerLimit = mTimerLimit - 1;

            TimeSpan ts = new TimeSpan(0, 0, mTimerLimit);

            mTimerValue = string.Format("{0}:{1:00}", ts.Minutes, ts.Seconds);

            Message msg = mHandler.ObtainMessage();

            Bundle b = new Bundle();

            b.PutString("text", mTimerValue);

            // Time's up
            if (mTimerLimit == 0)
            {
                b.PutString("STATE_LOSE", "" + (int)GameState.Lost);
                mTimerTask = null;

                mState = GameState.Lost;
            }
            else
            {
                mTimerTask = new CountDownTimerTask(this);
                mTimer.Schedule(mTimerTask, mTaskIntervalInMillis);
            }

            // This is how we send data back up to the main JetBoyView thread.
            // if you look in constructor of JetBoyView you will see code for
            // Handling of messages. This is borrowed directly from lunar lander.
            // Thanks again!
            msg.Data = b;
            mHandler.SendMessage(msg);
        }
Example #2
0
        public override void Run()
        {
            while (mRun)
            {
                Canvas c = null;

                if (mState == GameState.Running)
                {
                    // Process any input and apply it to the game state
                    UpdateGameState();

                    if (!mJetPlaying)
                    {
                        mInitialized = false;

                        Log.Debug(TAG, "------> STARTING JET PLAY");

                        mJet.Play();
                        mJetPlaying = true;
                    }

                    mPassedTime = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;

                    // Kick off the timer task for counter update
                    // if not already initialized
                    if (mTimerTask == null)
                    {
                        mTimerTask = new CountDownTimerTask(this);

                        mTimer.Schedule(mTimerTask, mTaskIntervalInMillis);
                    }
                }
                else if (mState == GameState.Play && !mInitialized)
                {
                    SetInitialGameState();
                }
                else if (mState == GameState.Lost)
                {
                    mInitialized = false;
                }

                try {
                    c = mSurfaceHolder.LockCanvas(null);

                    lock (mSurfaceHolder)
                        DoDraw(c);
                } finally {
                    // do this in a finally so that if an exception is thrown
                    // during the above, we don't leave the Surface in an
                    // inconsistent state
                    if (c != null)
                    {
                        mSurfaceHolder.UnlockCanvasAndPost(c);
                    }
                }
            }
        }
        // Does the work of updating timer
        internal void DoCountDown()
        {
            mTimerLimit = mTimerLimit - 1;

            TimeSpan ts = new TimeSpan (0, 0, mTimerLimit);
            mTimerValue = string.Format ("{0}:{1:00}", ts.Minutes, ts.Seconds);

            Message msg = mHandler.ObtainMessage ();

            Bundle b = new Bundle ();
            b.PutString ("text", mTimerValue);

            // Time's up
            if (mTimerLimit == 0) {
                b.PutString ("STATE_LOSE", "" + (int)GameState.Lost);
                mTimerTask = null;

                mState = GameState.Lost;
            } else {
                mTimerTask = new CountDownTimerTask (this);
                mTimer.Schedule (mTimerTask, mTaskIntervalInMillis);
            }

            // This is how we send data back up to the main JetBoyView thread.
            // if you look in constructor of JetBoyView you will see code for
            // Handling of messages. This is borrowed directly from lunar lander.
            // Thanks again!
            msg.Data = b;
            mHandler.SendMessage (msg);
        }
        public override void Run()
        {
            while (mRun) {
                Canvas c = null;

                if (mState == GameState.Running) {
                    // Process any input and apply it to the game state
                    UpdateGameState ();

                    if (!mJetPlaying) {
                        mInitialized = false;

                        Log.Debug (TAG, "------> STARTING JET PLAY");

                        mJet.Play ();
                        mJetPlaying = true;
                    }

                    mPassedTime = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;

                    // Kick off the timer task for counter update
                    // if not already initialized
                    if (mTimerTask == null) {
                        mTimerTask = new CountDownTimerTask (this);

                        mTimer.Schedule (mTimerTask, mTaskIntervalInMillis);
                    }
                } else if (mState == GameState.Play && !mInitialized) {
                    SetInitialGameState ();
                } else if (mState == GameState.Lost) {
                    mInitialized = false;
                }

                try {
                    c = mSurfaceHolder.LockCanvas (null);

                    lock (mSurfaceHolder)
                    DoDraw (c);
                } finally {
                    // do this in a finally so that if an exception is thrown
                    // during the above, we don't leave the Surface in an
                    // inconsistent state
                    if (c != null)
                        mSurfaceHolder.UnlockCanvasAndPost (c);
                }
            }
        }