コード例 #1
0
        /// <summary>
        /// Method for handling common code for playing levels
        /// </summary>
        private void PlayLevels()
        {
            PuzzlePlayer player = new PuzzlePlayer(mPuzzlePanel, sCurrentLvl);

            player.Play(mImage, this);
            mStatus            = "In-Game";
            mBtnPlay.Text      = "Pause";
            mBtnBrowse.Enabled = false;
            FlipCard();
            sIsFixed     = false;
            mCurrentMode = mMode;

            if (mMode == "Competitive")
            {
                mSwaps = 0;
                mTime  = "00:00";
            }
            else
            {
                mSwaps = -1;
                mTime  = "∞";
            }

            if (mMode == "Competitive")
            {
                mMin  = mSec = mTimeInSeconds = 0;
                mTime = "00:00";
            }
            mStatusTimer.Enabled = true;                                  // Start the status timer
            StatusCardFrontFragment.TimeControl(mTime);
            mDrawer.SetDrawerLockMode(DrawerLayout.LockModeLockedClosed); // Lock the navigation drawer
        }
コード例 #2
0
        /// <summary>
        /// Handles the Timer Elipsed event of statusTimer
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnTimedEvent(object sender, ElapsedEventArgs e)
        {
            mTimeInSeconds++;
            if (mMode == "Competitive")
            {
                mSec++;
                if (mSec == 60)
                {
                    mSec = 0;
                    mMin++;
                }

                mTime = $"{ mMin.ToString("00") }:{ mSec.ToString("00") }";
                RunOnUiThread(() => StatusCardFrontFragment.TimeControl(mTime));

                // Basic validation
                if (mMin == 59 && mSec == 59)
                {
                    mStatusTimer.Enabled = false;
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Handles BtnPlay click event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MBtnPlay_Click(object sender, EventArgs e)
        {
            PuzzlePlayer player = new PuzzlePlayer(mPuzzlePanel, sCurrentLvl);

            if (mBtnPlay.Text == "Play")
            {
                #region Play button click event
                player.Play(mImage, this);
                if (sCurrentLvl == LVL_1_NUM)
                {
                    mLvl = "Level 1";
                }
                else if (sCurrentLvl == LVL_2_NUM)
                {
                    mLvl = "Level 2";
                }
                else if (sCurrentLvl == LVL_3_NUM)
                {
                    mLvl = "Level 3";
                }
                else
                {
                    mLvl = "Level 4";
                }
                mStatus       = "In-Game";
                mBtnPlay.Text = "Pause";
                Drawable img = ContextCompat.GetDrawable(this, Resource.Drawable.ic_pause_white);
                mBtnPlay.SetCompoundDrawablesWithIntrinsicBounds(img, null, null, null); // Set button icon
                mBtnBrowse.Enabled = false;
                mBtnBrowse.SetBackgroundResource(Resource.Drawable.btn_disabled_style);
                mStatusTimer.Enabled = true; // Start the status timer
                if (mMode == "Competitive")
                {
                    mSwaps = 0;
                    mMin   = mSec = mTimeInSeconds = 0;
                    mTime  = "00:00";
                }
                else
                {
                    mSwaps = -1;
                }
                StatusCardFrontFragment.StatusVisibility(true);
                mDrawer.SetDrawerLockMode(DrawerLayout.LockModeLockedClosed); // Lock the navigation drawer
                #endregion
            }
            else if (mBtnPlay.Text == "Pause")
            {
                #region Pause button click event
                mPuzzlePanel.RemoveAllViews();
                mPuzzlePanel.AddView(mLayoutProgress);
                mPuzzlePanel.AddView(mLayoutMessage);
                mPuzzlePanel.AddView(mPicBoxWhole);
                mStatus       = "Paused";
                mBtnPlay.Text = "Retry";
                Drawable img = ContextCompat.GetDrawable(this, Resource.Drawable.ic_replay_white);
                mBtnPlay.SetCompoundDrawablesWithIntrinsicBounds(img, null, null, null); // Set button icon
                mBtnBrowse.Enabled = true;
                mBtnBrowse.SetBackgroundResource(Resource.Drawable.btn_orange_style);
                if (mShowingBack)
                {
                    FlipCard();
                }
                sIsFixed             = false;
                mStatusTimer.Enabled = false;
                StatusCardFrontFragment.StatusVisibility(false);
                mDrawer.SetDrawerLockMode(DrawerLayout.LockModeUnlocked); // Unlock the navigation drawer
                #endregion
            }
            else if (mBtnPlay.Text == "Retry")
            {
                #region Retry button click event
                player.Play(mImage, this);
                if (sCurrentLvl == LVL_1_NUM)
                {
                    mLvl = "Level 1";
                }
                else if (sCurrentLvl == LVL_2_NUM)
                {
                    mLvl = "Level 2";
                }
                else if (sCurrentLvl == LVL_3_NUM)
                {
                    mLvl = "Level 3";
                }
                else
                {
                    mLvl = "Level 4";
                }
                mStatus       = "In-Game";
                mBtnPlay.Text = "Pause";
                Drawable img = ContextCompat.GetDrawable(this, Resource.Drawable.ic_pause_white);
                mBtnPlay.SetCompoundDrawablesWithIntrinsicBounds(img, null, null, null); // Set button icon
                mBtnBrowse.Enabled = false;
                mBtnBrowse.SetBackgroundResource(Resource.Drawable.btn_disabled_style);
                mStatusTimer.Enabled = true; // Start the status timer
                if (mMode == "Competitive")
                {
                    mSwaps = 0;
                    mMin   = mSec = mTimeInSeconds = 0;
                    mTime  = "00:00";
                }
                else
                {
                    mSwaps = -1;
                }
                StatusCardFrontFragment.StatusVisibility(true);
                mDrawer.SetDrawerLockMode(DrawerLayout.LockModeLockedClosed); // Lock the navigation drawer
                #endregion
            }

            mCurrentMode = mMode;
            StatusCardFrontFragment.StatusControl(mLvl, mCurrentMode, mStatus);
            StatusCardFrontFragment.SwapsControl(mSwaps);
            StatusCardFrontFragment.TimeControl(mTime);
        }
コード例 #4
0
        /// <summary>
        /// Method for flipping status card fragments
        /// </summary>
        public void FlipCard()
        {
            if (sIsFixed)
            {
                // Check whether the puzzle is fixed
                if (mShowingBack)
                {
                    // Pop back to the last fragment on the stack (the front side fragment)
                    FragmentManager.PopBackStack();
                    mShowingBack = false;

                    // Set a timer to delay the execution til the flip is triggered
                    Timer delayedTimer = new Timer
                    {
                        Interval = 1,
                        Enabled  = true
                    };
                    delayedTimer.Start();

                    delayedTimer.Elapsed += (object sender, ElapsedEventArgs e) =>
                    {
                        delayedTimer.Stop();
                        RunOnUiThread(() =>
                        {
                            // Execute on UI thread
                            if (mStatus != "Paused")
                            {
                                StatusCardFrontFragment.StatusVisibility(true);
                            }
                            StatusCardFrontFragment.StatusControl(mLvl, mCurrentMode, mStatus);
                            StatusCardFrontFragment.SwapsControl(mSwaps);
                            StatusCardFrontFragment.TimeControl(mTime);
                        });
                        // Dispose time since it will no longer be used.
                        delayedTimer.Dispose();
                    };
                }
                else
                {
                    // The front is showing, therefore flip to back
                    FragmentTransaction transaction = FragmentManager.BeginTransaction();

                    // Set the custom animations
                    transaction.SetCustomAnimations(Resource.Animation.card_flip_right_in, Resource.Animation.card_flip_right_out,
                                                    Resource.Animation.card_flip_left_in, Resource.Animation.card_flip_left_out);

                    // Replace the fragment
                    transaction.Replace(Resource.Id.container, new StatusCardBackFragment());
                    transaction.AddToBackStack(null);
                    transaction.Commit();
                    mShowingBack = true;

                    // Set a timer to delay the execution til the flip is triggered
                    Timer delayedTimer = new Timer
                    {
                        Interval = 1,
                        Enabled  = true
                    };
                    delayedTimer.Start();

                    delayedTimer.Elapsed += (object sender, ElapsedEventArgs e) =>
                    {
                        delayedTimer.Stop();
                        RunOnUiThread(() =>
                        {
                            // Execute on UI thread
                            StatusCardBackFragment.LvlControl(sCurrentLvl, mTimeInSeconds, mSwaps, mMode);
                        });
                        // Dispose time since it will no longer be used.
                        delayedTimer.Dispose();
                    };
                }
            }
        }