bool FindNextTarget() { m_CurBounce++; if (m_CurBounce >= m_BounceNum) { return(false); } int w = m_BG.GetCoordW(); int h = m_BG.GetCoordH(); for (int x = 0; x < w; x++) { for (int y = 0; y < h; y++) { Coord2D coord = new Coord2D((x + m_TargetCoord.x) % w, y); GameObject obj = m_BG.GetElementByCoord(coord); if (obj == null) { continue; } BoxElementControl objControl = obj.GetComponent <BoxElementControl>(); if (objControl.m_Type == m_TargetType && objControl.GetState() != BoxState.ELIMINATE) { m_Target = obj; m_TargetCoord = coord; return(true); } } } return(false); }
public bool IsReachTop() { int w = m_BG.GetCoordW(); int h = m_BG.GetCoordH(); for (int x = 0; x < w; x++) { GameObject obj = m_BG.GetElementByCoord(new Coord2D(x, h - 1)); if (obj) { BoxElementControl bec = obj.GetComponent <BoxElementControl>(); if (bec.GetState() == BoxState.FIX) { return(true); //element fixed at top } } } return(false); }
public void EliminateRow(int row) { int w = m_BG.GetCoordW(); for (int x = 0; x < w; x++) { GameObject obj = m_BG.GetElementByCoord(new Coord2D(x, row)); if (!obj) { continue; } BoxElementControl control = obj.GetComponent <BoxElementControl>(); control.DestroyElement(); } }
public bool CheckEliminate(MoveDir dir) { if (m_State != BoxState.FIX) { return(false); } int w = m_BG.GetCoordW(); int h = m_BG.GetCoordH(); int matchNum = 1; switch (dir) { case MoveDir.UP: for (int y = m_CurCoord.y + 1; y < h; y++) { if (IsMatch(new Coord2D(m_CurCoord.x, y))) { matchNum++; } else { break; } } if (matchNum >= 3) { for (int y = 0; y < matchNum; y++) { MarkEliminate(new Coord2D(m_CurCoord.x, m_CurCoord.y + y)); } return(true); } else { return(false); } //break; case MoveDir.RIGHT: for (int x = m_CurCoord.x + 1; x < w; x++) { if (IsMatch(new Coord2D(x, m_CurCoord.y))) { matchNum++; } else { break; } } if (matchNum >= 3) { for (int x = 0; x < matchNum; x++) { MarkEliminate(new Coord2D(m_CurCoord.x + x, m_CurCoord.y)); } return(true); } else { return(false); } //break; case MoveDir.DOWN: for (int y = m_CurCoord.y - 1; y >= 0; y--) { if (IsMatch(new Coord2D(m_CurCoord.x, y))) { matchNum++; } else { break; } } if (matchNum >= 3) { for (int y = 0; y < matchNum; y++) { MarkEliminate(new Coord2D(m_CurCoord.x, m_CurCoord.y - y)); } return(true); } else { return(false); } //break; case MoveDir.LEFT: for (int x = m_CurCoord.x - 1; x >= 0; x--) { if (IsMatch(new Coord2D(x, m_CurCoord.y))) { matchNum++; } else { break; } } if (matchNum >= 3) { for (int x = 0; x < matchNum; x++) { MarkEliminate(new Coord2D(m_CurCoord.x - x, m_CurCoord.y)); } return(true); } else { return(false); } //break; default: return(false); } }