private bool controlNeighbours(int x, int y, hexagon.otherHexes hexes) //if a neighbour exists calls a switchAndMatchForLock function for it. { if (hexes.up.x >= 0 && hexes.up.x < hexGrid.GridWidth && hexes.up.y >= 0 && hexes.up.y < hexGrid.GridHeight) { if (switchAndMatchForLock(x, y, hexes.up) == true) { return(true); } } else if (hexes.upRight.x >= 0 && hexes.upRight.x < hexGrid.GridWidth && hexes.upRight.y >= 0 && hexes.upRight.y < hexGrid.GridHeight) { if (switchAndMatchForLock(x, y, hexes.upRight) == true) { return(true); } } else if (hexes.downRight.x >= 0 && hexes.downRight.x < hexGrid.GridWidth && hexes.downRight.y >= 0 && hexes.downRight.y < hexGrid.GridHeight) { if (switchAndMatchForLock(x, y, hexes.downRight) == true) { return(true); } } else if (hexes.down.x >= 0 && hexes.down.x < hexGrid.GridWidth && hexes.down.y >= 0 && hexes.down.y < hexGrid.GridHeight) { if (switchAndMatchForLock(x, y, hexes.down) == true) { return(true); } } else if (hexes.downLeft.x >= 0 && hexes.downLeft.x < hexGrid.GridWidth && hexes.downLeft.y >= 0 && hexes.downLeft.y < hexGrid.GridHeight) { if (switchAndMatchForLock(x, y, hexes.downLeft) == true) { return(true); } } else if (hexes.upLeft.x >= 0 && hexes.upLeft.x < hexGrid.GridWidth && hexes.upLeft.y >= 0 && hexes.upLeft.y < hexGrid.GridHeight) { if (switchAndMatchForLock(x, y, hexes.upLeft) == true) { return(true); } } return(false); }
private void otherTwoHex(out Vector2 firstHex, out Vector2 secondHex) //find the two hexes for selectedGroup { hexagon.otherHexes neighbours = selectedHexagon.GetComponent <hexagon>().getNeighbours(); bool isFind = false; do { switch (SelectCount) //other hexes depends on the SelectCount { case 0: firstHex = neighbours.up; secondHex = neighbours.upRight; break; case 1: firstHex = neighbours.upRight; secondHex = neighbours.downRight; break; case 2: firstHex = neighbours.downRight; secondHex = neighbours.down; break; case 3: firstHex = neighbours.down; secondHex = neighbours.downLeft; break; case 4: firstHex = neighbours.downLeft; secondHex = neighbours.upLeft; break; case 5: firstHex = neighbours.upLeft; secondHex = neighbours.up; break; default: firstHex = Vector2.zero; secondHex = Vector2.zero; break; } //if the hex is not available in the grid we increase the selectCount if (firstHex.x < 0 || firstHex.x >= GridWidth || firstHex.y < 0 || firstHex.y >= GridHeight || secondHex.x < 0 || secondHex.x >= GridWidth || secondHex.y < 0 || secondHex.y >= GridHeight) { SelectCount++; if (SelectCount >= 6) { SelectCount = 0; } } else { isFind = true; } } while (!isFind); }
public bool isLocked() //get every hexagons neighbours and test them. After that returns if there is deadlock or not { for (int i = 0; i < hexGrid.GridWidth; i++) { for (int j = 0; j < hexGrid.GridHeight; j++) { if (hexGrid.allHexagons[i, j] != null) { currentHex = hexGrid.allHexagons[i, j]; currentNeighbours = currentHex.GetComponent <hexagon>().getNeighbours(); if (controlNeighbours(i, j, currentNeighbours) == true) { isDeadLocked = false; return(false); } } } } isDeadLocked = true; return(true); }