public void IsWalkableReturnsTrueForWalkableTiles()
        {
            File.WriteAllText("data/config.json", "{ 'PuzzlePushProbability': 0 }");
            new Config("data/config.json");

            var floor      = new CaveFloorMap(MapWidth, MapHeight);
            var foundFloor = false;
            var foundWall  = false;

            // There must be at least one walkable tile and one non-walkable tile, based on the current generation strategy
            for (var x = 0; x < MapWidth; x++)
            {
                for (var y = 0; y < MapHeight; y++)
                {
                    var walkable = floor.IsWalkable(x, y);
                    if (walkable)
                    {
                        foundFloor = true;
                    }
                    else
                    {
                        foundWall = true;
                    }
                }
            }

            Assert.That(foundFloor, Is.EqualTo(true));
            Assert.That(foundWall, Is.EqualTo(true));
        }
示例#2
0
        public Monster(ColourTuple colour, int agility, string visionType, int visionSize, CaveFloorMap map) : base('m', colour, true)
        {
            this.Agility    = agility;
            this.VisionType = visionType;
            this.VisionSize = visionSize;

            Monster.map  = map;
            this.goal    = map.FindEmptyPosition();
            this.goalMap = this.CreateGoalMap();
        }
        public void ConstructorCreatesStairsDownAwayFromPlayer()
        {
            // Stairs are randomly positioned. To avoid a flaky test, just check if the distance is non-zero.
            var floor          = new CaveFloorMap(MapWidth, MapHeight);
            var playerPosition = floor.playerStartPosition;
            var stairsDown     = floor.StairsDownPosition;

            var distance = Math.Abs(playerPosition.X - stairsDown.X) + Math.Abs(playerPosition.Y - stairsDown.Y);

            Assert.That(distance, Is.GreaterThan(0));
        }
示例#4
0
        private void GenerateAndDisplayMap()
        {
            var playerView = this.objects.Single(g => g.Name == "Player");
            var mapWidth   = Config.Instance.Get <int>("MapWidth");
            var mapHeight  = Config.Instance.Get <int>("MapHeight");

            // Create the map
            this.currentMap = new CaveFloorMap(mapWidth, mapHeight);

            // Create the view
            var start = currentMap.AddPlayer(playerView.Data as Player);

            playerView.Position = new Point(start.X, start.Y);
            this.CenterViewToPlayer();

            var stairsDown = this.objects.Single(g => g.Name == "StairsDown");

            stairsDown.Move(currentMap.StairsDownPosition.X, currentMap.StairsDownPosition.Y);

            foreach (var obj in currentMap.Objects)
            {
                if (!this.objects.Any(o => o.Data == obj))
                {
                    this.CreateGameObject(string.Empty, obj);
                }
            }

            // Loop through the map information generated by RogueSharp and update our view
            for (var j = 0; j < mapHeight; j++)
            {
                for (var i = 0; i < mapWidth; i++)
                {
                    var tile = this[i, j];
                    this.CreateCellFor(i, j).CopyAppearanceTo(tile);
                    tile.ApplyEffect(HiddenEffect);
                }
            }
        }