/// <inheritdoc /> protected override void Update() { _freeCursorPosition = UnityEngine.Input.mousePosition; // TODO handle cursor leaving and entering window var newCursorPos = (Vector2Int)levelGrid.WorldToCell(camera.ScreenToWorldPoint(_freeCursorPosition)); if (newCursorPos != _currentCursorGridPos) { _withinLevelBounds = levelSettings == null || LevelUtility.IsCellWithinBounds(newCursorPos, levelSettings.size); _currentCursorGridPos = newCursorPos; normalClick.currentCursorGridPos = specialClick.currentCursorGridPos = _currentCursorGridPos; if (enabled) { onCellHovered.Invoke(_withinLevelBounds ? _currentCursorGridPos : null); } normalClick.OnCellHovered(_currentCursorGridPos); specialClick.OnCellHovered(_currentCursorGridPos); } base.Update(); if (UnityEngine.Input.GetKeyUp(frameKey)) { onFrameAction.Invoke(); } }
private void CheckAccess(int x, int y) { if (_cells == null) { throw new LevelTableException("Level not generated"); } if (!LevelUtility.IsCellWithinBounds(x, y, Size)) { throw new CellPositionOutOfRangeException(x, y); } }
public static void RevealCellsRecursively(LevelTable level, int x, int y, Dictionary <Vector2Int, Cell> revealList) { if (revealList.Count > level.CellCount) { throw new OverflowException(); } var pos = new Vector2Int(x, y); if (revealList.ContainsKey(pos)) { return; } if (!LevelUtility.IsCellWithinBounds(x, y, level.Size)) { return; // Indexes out of range. } Cell cell = level[x, y]; if (cell.isRevealed || cell.hasFlag) { return; // cell is not subject revelation. } level.MarkCellRevealed(pos); revealList[pos] = level[x, y]; if (cell.value == 0) { const int neighborCount = 8; var neighbors = ArrayPool <Vector2Int> .Get(neighborCount); LevelUtility.GetAdjacentCellsSquare(pos, neighbors); for (int i = 0; i < neighborCount; i++) { Vector2Int nPos = neighbors[i]; RevealCellsRecursively(level, nPos.x, nPos.y, revealList); } ArrayPool <Vector2Int> .Release(neighbors); } }