private bool ValidCell(int row, int col, ref Direction direction) { var cell = _map[row, col]; if (!cell.Is(RCell.Wall)) { return(false); } _directions.ShuffleList(); foreach (var dir in _directions) { direction = dir; var checkRow = row; var checkCol = col; RHelper.MoveInDirection(ref checkRow, ref checkCol, dir); var checkRowOpp = row; var checkColOpp = col; RHelper.MoveInDirection(ref checkRowOpp, ref checkColOpp, _oppositeDirections[dir]); if (_map[checkRow, checkCol].Is(RCell.Diggable) && _map[checkRowOpp, checkColOpp].Is(RCell.Walkable)) { return(true); } } return(false); }
private bool CheckAvailableSpace(int row, int col, Direction dir) { var topRow = row; var leftCol = col; GetTopLeftCorner(ref topRow, ref leftCol, dir); // We have to move one block away, or it's guaranteed to fail the check RHelper.MoveInDirection(ref topRow, ref leftCol, dir); for (var r = topRow; r < topRow + Height; ++r) { for (var c = leftCol; c < leftCol + Width; ++c) { if (r < 0 || r >= Map.Rows || c < 0 || c >= Map.Columns) { return(false); } if (!Map[r, c].Is(RCell.Diggable)) { return(false); } } } return(true); }
public override void GenerateImpl(int row, int col, Direction dir) { var topRow = row; var leftCol = col; GetTopLeftCorner(ref topRow, ref leftCol, dir); var goalRow = row; var goalCol = col; RHelper.MoveInDirection(ref goalRow, ref goalCol, dir); var digArea = new Rectangle(leftCol + 1, topRow + 1, Width - 2, Height - 2); var digger = new Digger(goalRow, goalCol, (int)((digArea.Width * digArea.Height) / 25d), Map); Map[row, col] = Map[row, col].Is(RCell.Important) ? RCell.Door | RCell.Important | RCell.Closed : RCell.Floor; digger.DigCell(row, col); digger.DigCell(row + 1, col); digger.DigCell(row - 1, col); digger.DigCell(row, col + 1); digger.DigCell(row, col - 1); digger.Dig(); }
public void Dig() { DigOut(); do { var dir = RHelper.GetRandomDirection(); var nextRow = _row; var nextCol = _col; RHelper.MoveInDirection(ref nextRow, ref nextCol, dir); if (!CanMove(nextRow, nextCol)) { continue; } _row = nextRow; _col = nextCol; if (!CanDig()) { continue; } DigOut(); ++_digged; } while (_digged < _digGoal); }
public bool ProcessTurn(int playerX, int playerY) { _map.SetWalkable(Position.X, Position.Y, true); _map.SetVisible(Position.X, Position.Y, true); _fovMap.CalculateFoV(Position.X, Position.Y, SightRadius); if (_fovMap.IsVisible(playerX, playerY)) { _fovMap.ComputePath(Position.X, Position.Y, playerX, playerY); } int wantX; int wantY; if (!_fovMap.PathAvailable()) { do { wantX = Position.X; wantY = Position.Y; RHelper.MoveInDirection(ref wantY, ref wantX, RHelper.GetRandomDirection()); } while (!_fovMap.IsWalkable(wantX, wantY)); } else { wantX = _position.X; wantY = _position.Y; _fovMap.WalkPath(ref wantX, ref wantY); } _position.X = wantX; _position.Y = wantY; var onPlayer = playerX == _position.X && playerY == _position.Y; _map.SetWalkable(_position.X, _position.Y, onPlayer); _map.SetVisible(_position.X, _position.Y, onPlayer); return(onPlayer); }