Exemplo n.º 1
0
        /// <summary>
        /// Find Block Pair
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Tuple FindBlockPair(int id)
        {
            Tuple tuple = new Tuple(this);

            for (int j = 1; j < Model.TOT_BLOCK_CNT_Y - 1; ++j)
            {
                for (int i = 1; i < Model.TOT_BLOCK_CNT_X - 1; ++i)
                {
                    if (_map[i][j].GetImageId() == id)
                    {
                        tuple.Select(new Position(i, j));
                        if (tuple.IsTuple())
                        {
                            return(tuple);
                        }
                    }
                }
            }
            return(null);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Mouse Left Click Handler For Game Round
        /// </summary>
        /// <param name="xMouse"></param>
        /// <param name="yMouse"></param>
        public void GameRoundLeftClickHandler(int xMouse, int yMouse)
        {
            // Check the game state
            if (_gameState != GameState.PLAYING)
            {
                return;
            }

            // Select a block
            int      x             = xMouse / (Model.BLOCK_SIZE_X + Model.BLOCK_MARGIN);
            int      y             = yMouse / (Model.BLOCK_SIZE_Y + Model.BLOCK_MARGIN);
            Position blockPosition = new Position(x, y);

            // Check selected block is valid
            if (_grid.GetBlock(blockPosition).IsNull())
            {
                return;
            }
            // Check tuple is selectable
            if (!_tuple.Select(blockPosition))
            {
                return;
            }

            // Check is connected AND required to merge
            if (_tuple.IsTuple())
            {
                Position startPos = _tuple.GetFirst();
                Position endPos   = _tuple.GetSecond();
                _tuple.Clear(); // Clear tuple

                if (_isConnected(startPos, endPos, _grid))
                {
                    // Connected, need to be merged
                    _grid.Merge(startPos, endPos);

                    _score.Merged();
                    _sePlayer.Merged(); // Merged SE

                    // Goto check game end
                    if (_gameEnd())
                    {
                        return;
                    }

                    // Check is there any block can be merged
                    AcquireResourceMutex(MutexType.TIP);
                    _mergableTuple       = new Tip();
                    _mergableTuple.Tuple = _findMergableBlockPair();
                    while (_mergableTuple.Tuple == null)
                    {
                        _grid.Randomize();
                        _sePlayer.Refresh(); // Refresh SE
                        _mergableTuple.Tuple = _findMergableBlockPair();
                    }
                    ReleaseResourceMutex(MutexType.TIP);
                }
                else
                {
                    _score.ComboInterrupted();
                    _sePlayer.Failed(); // Failed SE
                }
            }
            else
            {
                _sePlayer.Clicked(); // Click SE
            }
        }