Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        private void Move(int rows, int cols)
        {
            if (_fovMap.IsWalkable(_position.X + cols, _position.Y + rows))
            {
                _position.X += cols;
                _position.Y += rows;
                _statistics.AddToStatistic(Statistic.StepsTaken, 1);
            }

            var cell = _map[_position.Y, _position.X];

            if (cell.Is(RCell.Door) && cell.Is(RCell.Closed))
            {
                cell &= ~RCell.Closed;
                cell |= RCell.Open;
                _map[_position.Y, _position.X] = cell;
                _map.SetVisible(_position.X, _position.Y, true);
                _statistics.AddToStatistic(Statistic.DoorsOpened, 1);
            }

            RecaclulateFoV();
        }