三合一类游戏消除逻辑

来源:互联网 发布:手机淘宝怎么扫码付款 编辑:程序博客网 时间:2024/04/29 21:01
private void checkThreeToOne(int x, int y, int id){
for (int i = y - 1; i <= y + 1; i++) {
if (i != y) {
for (int j = x - 1; j < x + 1; j++) {
if (i < 0 || j < 0 || i > 5 || j + 1 > 5 || gameBack[i][j] == NONE) {
continue;
}
if (gameBack[i][j] == gameBack[i][j + 1] && gameBack[i][j] == id) {
for (int n = 0; n < m_vector.size(); n++) {
if (((NPC)m_vector.elementAt(n)).y == i) {
if (((NPC)m_vector.elementAt(n)).x == j) {
((NPC)m_vector.elementAt(n)).setDirection(STAY, y, x);
}
if (((NPC)m_vector.elementAt(n)).x == j + 1) {
((NPC)m_vector.elementAt(n)).setDirection(STAY, y, x);
}

}
}
}
}else{
for (int j = x - 2; j < x + 2; j++) {
if (i < 0 || j < 0 || i > 5 || j + 1 > 5 || gameBack[i][j] == NONE || j == x) {
continue;
}
if (j == x - 1) {
if (j + 2 < 6 && gameBack[i][j] == gameBack[i][j + 2] && gameBack[i][j] == id) {
for (int n = 0; n < m_vector.size(); n++) {
if (((NPC)m_vector.elementAt(n)).y == i) {
if (((NPC)m_vector.elementAt(n)).x == j) {
((NPC)m_vector.elementAt(n)).setDirection(STAY, y, x);
}
if (((NPC)m_vector.elementAt(n)).x == j + 2) {
((NPC)m_vector.elementAt(n)).setDirection(STAY, y, x);
}

}
}
}else{
if (gameBack[i][j] == gameBack[i][j + 1] && gameBack[i][j] == id) {
for (int n = 0; n < m_vector.size(); n++) {
if (((NPC)m_vector.elementAt(n)).y == i) {
if (((NPC)m_vector.elementAt(n)).x == j) {
((NPC)m_vector.elementAt(n)).setDirection(STAY, y, x);
}
if (((NPC)m_vector.elementAt(n)).x == j + 1) {
((NPC)m_vector.elementAt(n)).setDirection(STAY, y, x);
}

}
}
}
}
}
}

for (int i = x - 1; i <= x + 1; i++) {
if (i != x) {
for (int j = y - 1; j < y + 1; j++) {
if (i < 0 || j < 0 || i > 5 || j + 1 > 5 || gameBack[j][i] == NONE) {
continue;
}
if (gameBack[j][i] == gameBack[j + 1][i] && gameBack[j][i] == id) {
for (int n = 0; n < m_vector.size(); n++) {
if (((NPC)m_vector.elementAt(n)).x == i) {
if (((NPC)m_vector.elementAt(n)).y == j) {
((NPC)m_vector.elementAt(n)).setDirection(STAY, y, x);
}
if (((NPC)m_vector.elementAt(n)).y == j + 1) {
((NPC)m_vector.elementAt(n)).setDirection(STAY, y, x);
}

}
}
}
}else{
for (int j = y - 2; j < y + 2; j++) {
if (i < 0 || j < 0 || i > 5 || j + 1 > 5 || gameBack[j][i] == NONE || j == y) {
continue;
}
if (j == y - 1) {
if (j + 2 < 6 && gameBack[j][i] == gameBack[j + 2][i] && gameBack[j][i] == id) {
for (int n = 0; n < m_vector.size(); n++) {
if (((NPC)m_vector.elementAt(n)).x == i) {
if (((NPC)m_vector.elementAt(n)).y == j) {
((NPC)m_vector.elementAt(n)).setDirection(STAY, y, x);
}
if (((NPC)m_vector.elementAt(n)).y == j + 2) {
((NPC)m_vector.elementAt(n)).setDirection(STAY, y, x);
}

}
}
}else{
if (gameBack[j][i] == gameBack[j + 1][i] && gameBack[j][i] == id) {
for (int n = 0; n < m_vector.size(); n++) {
if (((NPC)m_vector.elementAt(n)).x == i) {
if (((NPC)m_vector.elementAt(n)).y == j) {
((NPC)m_vector.elementAt(n)).setDirection(STAY, y, x);
}
if (((NPC)m_vector.elementAt(n)).y == j + 1) {
((NPC)m_vector.elementAt(n)).setDirection(STAY, y, x);
}

}
}
}
}
}
}
if (x - 1 >= 0 && y - 1 >= 0 && gameBack[y][x - 1] == gameBack[y - 1][x] && gameBack[y][x - 1] == id) {
for (int n = 0; n < m_vector.size(); n++) {
if (((NPC)m_vector.elementAt(n)).y == y && ((NPC)m_vector.elementAt(n)).x == x - 1) {
((NPC)m_vector.elementAt(n)).setDirection(STAY, y, x);
}
if (((NPC)m_vector.elementAt(n)).y == y - 1 && ((NPC)m_vector.elementAt(n)).x == x) {
((NPC)m_vector.elementAt(n)).setDirection(STAY, y, x);
}

}
if (x - 1 >= 0 && y + 1 < 6 && gameBack[y][x - 1] == gameBack[y + 1][x] && gameBack[y][x - 1] == id) {
for (int n = 0; n < m_vector.size(); n++) {
if (((NPC)m_vector.elementAt(n)).y == y && ((NPC)m_vector.elementAt(n)).x == x - 1) {
((NPC)m_vector.elementAt(n)).setDirection(STAY, y, x);
}
if (((NPC)m_vector.elementAt(n)).y == y + 1 && ((NPC)m_vector.elementAt(n)).x == x) {
((NPC)m_vector.elementAt(n)).setDirection(STAY, y, x);
}

}

if (x + 1 < 6 && y + 1 < 6 && gameBack[y][x + 1] == gameBack[y + 1][x] && gameBack[y][x + 1] == id) {
for (int n = 0; n < m_vector.size(); n++) {
if (((NPC)m_vector.elementAt(n)).y == y && ((NPC)m_vector.elementAt(n)).x == x + 1) {
((NPC)m_vector.elementAt(n)).setDirection(STAY, y, x);
}
if (((NPC)m_vector.elementAt(n)).y == y + 1 && ((NPC)m_vector.elementAt(n)).x == x) {
((NPC)m_vector.elementAt(n)).setDirection(STAY, y, x);
}

}

if (x + 1 < 6 && y - 1 >= 0 && gameBack[y][x + 1] == gameBack[y - 1][x] && gameBack[y][x + 1] == id) {
for (int n = 0; n < m_vector.size(); n++) {
if (((NPC)m_vector.elementAt(n)).y == y && ((NPC)m_vector.elementAt(n)).x == x + 1) {
((NPC)m_vector.elementAt(n)).setDirection(STAY, y, x);
}
if (((NPC)m_vector.elementAt(n)).y == y - 1 && ((NPC)m_vector.elementAt(n)).x == x) {
((NPC)m_vector.elementAt(n)).setDirection(STAY, y, x);
}

}
0 0