矩阵游戏,当用户选择2个相同颜色的球时,它应该破坏2个相同颜色的图案
matrix game, condition when user selects 2 same colored balls it should destroy the 2 same color patterns
我正在尝试一个矩阵游戏,条件是:
- 当用户选择2个相同颜色的球时,将破坏2个相同颜色的图案。
我已经做了横向&垂直选择正确。但是当我尝试交叉选择(对角线)它不工作,我想,我已经做了一个错误的对角线选择条件。
这是我的编码,交叉选择不匹配相同的颜色模式。这是我的对角线选择编码,以下条件是否正确?
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逗号操作符的工作方式,它被解释为else if (d)
,因此如果d
不为零,isAdjacent
将被设置为true
。
试
else if (this.mFirstCheckPattern.m_nRowIndex + 1 == this.mSecondCheckPattern.m_nRowIndex && this.mFirstCheckPattern.m_nColIndex - 1 == this.mSecondCheckPattern.m_nColIndex)
。
相关文章:
- jsf中两个字符串的颜色代码差异
- JS-颜色选择器只有第一个工作
- 如何使用带有多个按钮的javascript更改按钮颜色
- 如何从onClick更改多个SVG节点的颜色
- 为什么可以't我在highstocks.js中的蜡烛图中获得超过55个条形的单个条形颜色
- 画布-在多个画布叠加中获取像素颜色
- 第n个子项和第n类型的行颜色交替
- 使用1个javascript更改按钮的背景颜色
- jQuery每5个工作小时重置一次颜色模式
- 在Rails中,如何通过单击其中一个页面上的按钮来更改三个独立页面上边框的颜色
- 在画布上绘制两个不同颜色的形状
- 具有多个选择框的多种选项颜色
- DevExpress 多个列表框丢失焦点颜色效果
- 谷歌图表仪表与多个颜色区域
- 如何在运行时使用css更改和维护多个颜色主题
- 如何显示两个颜色框(弹出窗口)
- 对于谷歌地图标记,是否可以在svg中包含多个颜色
- iframe中的多个颜色框
- 添加第二个颜色选择器
- Zoomcharts 1.5.1 -如何在单个链接上显示多个颜色/多个悬停