public static void SetReachableBlocks(GroundPiece groundPiece, Snake snake) { if (groundPiece.tempReachableState == true || groundPiece.collectingSnake == snake || groundPiece.IsBoundPiece()) { return; } groundPiece.tempReachableState = true; try { SetReachableBlocks(groundPiece.GroundPieceOnOvest(), snake); } catch { } try { SetReachableBlocks(groundPiece.GroundPieceOnEst(), snake); } catch { } try { SetReachableBlocks(groundPiece.GroundPieceOnNorth(), snake); } catch { } try { SetReachableBlocks(groundPiece.GroundPieceOnSouth(), snake); } catch { } }
public static void FloodFill(GroundPiece groundPiece, int before, int after) { if (groundPiece.ownerIDForCheck != before || !groundPiece.tempHasToBeChecked) { return; } groundPiece.ownerIDForCheck = after; try { FloodFill(groundPiece.GroundPieceOnOvest(), before, after); } catch { } try { FloodFill(groundPiece.GroundPieceOnEst(), before, after); } catch { } try { FloodFill(groundPiece.GroundPieceOnNorth(), before, after); } catch { } try { FloodFill(groundPiece.GroundPieceOnSouth(), before, after); } catch { } }
public HashSet <Vector3> GetDirectionsToExclude() { Vector3 up = transform.up; Vector3 down = -transform.up; Vector3 right = transform.right; Vector3 left = -transform.right; HashSet <Vector3> dirToExclude = new HashSet <Vector3> (); try { if (lastReachedGroundPiece.GroundPieceOnEst().collectingSnake == snake || lastReachedGroundPiece.GroundPieceOnEst().IsBoundPiece()) { dirToExclude.Add(transform.right); } } catch { dirToExclude.Add(transform.right); } try { if (lastReachedGroundPiece.GroundPieceOnOvest().collectingSnake == snake || lastReachedGroundPiece.GroundPieceOnOvest().IsBoundPiece()) { dirToExclude.Add(-transform.right); } } catch { dirToExclude.Add(-transform.right); } try { if (lastReachedGroundPiece.GroundPieceOnNorth().collectingSnake == snake || lastReachedGroundPiece.GroundPieceOnNorth().IsBoundPiece()) { dirToExclude.Add(transform.up); } } catch { dirToExclude.Add(transform.up); } try { if (lastReachedGroundPiece.GroundPieceOnSouth().collectingSnake == snake || lastReachedGroundPiece.GroundPieceOnSouth().IsBoundPiece()) { dirToExclude.Add(-transform.up); } } catch { dirToExclude.Add(-transform.up); } return(dirToExclude); }
public static bool CheckIfCanGoInDirection(GroundPiece groundPieceToCheck, Vector3 dir, Snake snake) { bool canGoInDirection = false; if (dir == Vector3.up) { try { SetReachableBlocks(groundPieceToCheck.GroundPieceOnNorth(), snake); } catch { } } if (dir == -Vector3.up) { try { SetReachableBlocks(groundPieceToCheck.GroundPieceOnSouth(), snake); } catch { } } if (dir == Vector3.right) { try { SetReachableBlocks(groundPieceToCheck.GroundPieceOnEst(), snake); } catch { } } if (dir == -Vector3.right) { try { SetReachableBlocks(groundPieceToCheck.GroundPieceOnOvest(), snake); } catch { } } foreach (GroundPiece piece in GroundSpawner.instance.rows[1].groundPieces) { if (piece.tempReachableState == true && piece.collectingSnake != snake) { canGoInDirection = true; } } foreach (GroundPiece piece in GroundSpawner.instance.rows[GroundSpawner.instance.rows.Length - 2].groundPieces) { if (piece.tempReachableState == true && piece.collectingSnake != snake) { canGoInDirection = true; } } foreach (GroundPiece piece in GroundSpawner.instance.columns[1].groundPieces) { if (piece.tempReachableState == true && piece.collectingSnake != snake) { canGoInDirection = true; } } foreach (GroundPiece piece in GroundSpawner.instance.columns[GroundSpawner.instance.columns.Length - 2].groundPieces) { if (piece.tempReachableState == true && piece.collectingSnake != snake) { canGoInDirection = true; } } foreach (GroundPiece piece in GroundSpawner.instance.spawnedGroundPieces) { piece.tempReachableState = false; } return(canGoInDirection); }