Matrix game, a condition when the user selects 2 identical colored balls, he must destroy 2 identical color patterns

I am trying to use a matrix game, condition:

  • when the user selects 2 identical colors of the ball, which will destroy 2 identical color patterns.

I made the right horizontal and vertical selection. But when I try to cross-select (diagonal) it doesn't work, I think I was wrong about the diagonal selection.

This is my coding, the selection of the cross does not match the same color pattern. This is my diagonal selectin coding, is the following condition true?

    onCheckPattern: function(pPattern) {
    if (pPattern != null) {
        this.mPromptTimerTally = 0;
        this.mPromptMarkSpr.setPosition(-1000.0, -1000.0);

        if (this.mFirstCheckPattern === null) {
            this.mFirstCheckPattern = pPattern;
            this.mCheckMarkSpr.setPosition(this.mPatternsPos[this.mFirstCheckPattern.m_nRowIndex][this.mFirstCheckPattern.m_nColIndex]);
        } else {
            this.mSecondCheckPattern = pPattern;
            if (this.mSecondCheckPattern === this.mFirstCheckPattern) {
                //                    this.mSecondCheckPattern = null;
                //                    return;
            }

            var isAdjacent = false;

            //HORIZONTAL& VERTICAL
            if (this.mFirstCheckPattern.m_nRowIndex == this.mSecondCheckPattern.m_nRowIndex) {
                if (this.mFirstCheckPattern.m_nColIndex > 0 &&
                    this.mFirstCheckPattern.m_nColIndex - 1 == this.mSecondCheckPattern.m_nColIndex)
                    isAdjacent = true;

                else if (this.mFirstCheckPattern.m_nColIndex + 1 < this.m_nMatrixCol &&
                    this.mFirstCheckPattern.m_nColIndex + 1 == this.mSecondCheckPattern.m_nColIndex)
                    isAdjacent = true;
            } else if (this.mFirstCheckPattern.m_nColIndex == this.mSecondCheckPattern.m_nColIndex) {
                if (this.mFirstCheckPattern.m_nRowIndex > 0 &&
                    this.mFirstCheckPattern.m_nRowIndex - 1 == this.mSecondCheckPattern.m_nRowIndex)
                    isAdjacent = true;
                else if (this.mFirstCheckPattern.m_nRowIndex + 1 < this.m_nMatrixRow &&
                    this.mFirstCheckPattern.m_nRowIndex + 1 == this.mSecondCheckPattern.m_nRowIndex)
                    isAdjacent = true;

            }
            //       


            //DIAGONAL SELECTION
            else if (this.mFirstCheckPattern.m_nRowIndex + 1, this.mFirstCheckPattern.m_nColIndex - 1 && this.mSecondCheckPattern.m_nRowIndex, this.mSecondCheckPattern.m_nColIndex)

            {
                isAdjacent = true;
            } else if (this.mFirstCheckPattern.m_nRowIndex - 1 == this.mSecondCheckPattern.m_nRowIndex && this.mFirstCheckPattern.m_nColIndex - 1 == this.mSecondCheckPattern.m_nColIndex) {
                isAdjacent = true;
            }




            if (isAdjacent) {
                this.mCheckMarkSpr.setPosition(-1000.0, -1000.0);

                this.swapTwoPattern(this.mFirstCheckPattern, this.mSecondCheckPattern, false);
                this.mFirstCheckPattern = null;
                this.mSecondCheckPattern = null;
            } else {
                this.mCheckMarkSpr.setPosition(this.mPatternsPos[this.mSecondCheckPattern.m_nRowIndex][this.mSecondCheckPattern.m_nColIndex]);

                this.mFirstCheckPattern = this.mSecondCheckPattern;
                this.mSecondCheckPattern = null;
            }
        }
    }
},

      

+3


source to share


1 answer


Line

            else if (this.mFirstCheckPattern.m_nRowIndex + 1, this.mFirstCheckPattern.m_nColIndex - 1 && this.mSecondCheckPattern.m_nRowIndex, this.mSecondCheckPattern.m_nColIndex)

      

looks suspicious to me.

An abbreviation for multiple, you write something like

            else if (a + 1, b - 1 && c, d)

      



Because of the way JavaScript comma works , this is interpreted as else if (d)

, so isAdjacent

will be set to true

if d

not zero.

Try

            else if (this.mFirstCheckPattern.m_nRowIndex + 1 == this.mSecondCheckPattern.m_nRowIndex && this.mFirstCheckPattern.m_nColIndex - 1 == this.mSecondCheckPattern.m_nColIndex)

      

instead.

0


source







All Articles