Ejemplo n.º 1
0
    void CreatePuzzle(bool addInitialElements = false)
    {
        Puzzle puzzle = new Puzzle();

        if (puzzleFront)
        {
            Destroy(puzzleFront.gameObject);
        }
        puzzleFront = Instantiate(puzzleFrontPrefab) as PuzzleFront;
        puzzleFront.CreatePuzzle(puzzle);
        puzzle.addEdge        += e => DirtyPuzzle();
        puzzle.removeEdge     += e => DirtyPuzzle();
        puzzle.addElement     += e => DirtyPuzzle();
        puzzle.removeElement  += e => DirtyPuzzle();
        puzzle.addItem        += e => DirtyPuzzle();
        puzzle.removeItem     += e => DirtyPuzzle();
        puzzle.addNode        += e => DirtyPuzzle();
        puzzle.removeNode     += e => DirtyPuzzle();
        puzzle.addReceiver    += (e, f) => DirtyPuzzle();
        puzzle.removeReceiver += (e, f) => DirtyPuzzle();

        if (addInitialElements)
        {
            PuzzleNode   node   = new PuzzleNode();
            PuzzlePlayer player = new PuzzlePlayer();
            player.defaultNode = node;
            puzzle.AddNode(node);
            puzzle.AddItem(player);
        }

        RefreshData();
    }
Ejemplo n.º 2
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
        }
Ejemplo n.º 3
0
    public void CheckIsGoal(PuzzleStateNode node)
    {
        bool anyPlayers       = false;
        bool allPlayersInGoal = true;

        foreach (PuzzleItem item in items)
        {
            PuzzlePlayer player = item as PuzzlePlayer;
            if (player == null)
            {
                continue;
            }
            anyPlayers = true;
            PuzzleElement element = player.GetNode(this, node.state).element;
            if (element == null || !(element is PuzzleGoal))
            {
                allPlayersInGoal = false;
            }
        }
        node.goal = false;
        if (anyPlayers && allPlayersInGoal)
        {
            node.goal = true;
            if (goalPathSteps > 0)
            {
                goalPathSteps = Math.Min(goalPathSteps, node.step);
            }
            else
            {
                goalPathSteps = node.step;
            }
            goalStates++;
        }
    }
Ejemplo n.º 4
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);
        }