gpt4 book ai didi

javascript - 矩阵游戏,条件是当用户选择 2 个相同颜色的球时,它应该破坏 2 个相同颜色的图案

转载 作者:行者123 更新时间:2023-12-04 02:17:47 25 4
gpt4 key购买 nike

我正在尝试一个矩阵游戏,条件是:

  • 当用户选择 2 个相同颜色的球时,这将破坏 2 个相同颜色的图案。

我已经正确完成了水平和垂直选择。但是当我尝试交叉选择(对 Angular 线)时它不起作用,我想,我在对 Angular 线选择条件下犯了一个错误。

这是我的代码,交叉选择没有匹配相同的颜色模式。这是我的对 Angular 线选择编码,下列条件是否正确?

    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;
}
}
}
},

最佳答案

线

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

我觉得很可疑。

稍微缩写一下,你正在写类似的东西

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

因为JavaScript comma operator的方式有效,这被解释为 else if (d),因此 isAdjacent 将被设置为 true if d不为零。

尝试

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

相反。

关于javascript - 矩阵游戏,条件是当用户选择 2 个相同颜色的球时,它应该破坏 2 个相同颜色的图案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25459803/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com