Beispiel #1
0
		private Cell GetRandomEmptyCell()
		{
			IRandom random = new DotNetRandom();

			while (true)
			{
				int x = random.Next(width - 1);
				int y = random.Next(height - 1);
				if (_map.IsWalkable(x, y))
				{
					return _map.GetCell(x, y);
				}
			}
		}
        public void Restore_AfterGeneratingThreeNumbers_RegeneratesSameThreeNumbers()
        {
            IRandom random = new DotNetRandom();
             for ( int i = 0; i < 25; i++ )
             {
            random.Next( 1000 );
             }
             RandomState state = random.Save();
             int first = random.Next( 1000 );
             int second = random.Next( 1000 );
             int third = random.Next( 1000 );

             random.Restore( state );

             Assert.AreEqual( first, random.Next( 1000 ) );
             Assert.AreEqual( second, random.Next( 1000 ) );
             Assert.AreEqual( third, random.Next( 1000 ) );
        }
Beispiel #3
0
        public void Create_MapCreatedWithRandomRoomsMapCreationStrategy_ExpectedMap()
        {
            int expectedWidth = 17;
             int expectedHeight = 10;
             IRandom random = new DotNetRandom( 13 );
             IMapCreationStrategy<LibtcodMap> mapCreationStrategy = new RandomRoomsMapCreationStrategy<LibtcodMap>( expectedWidth, expectedHeight, 30, 5, 3, random );
             string expectedMapRepresentation = @"#################
                                              #################
                                              ##...#######...##
                                              ##.............##
                                              ###.###....#...##
                                              ###...##.#####.##
                                              ###...##...###..#
                                              ####............#
                                              ##############..#
                                              #################";

             IMap actualMap = LibtcodMap.Create( mapCreationStrategy );
             Trace.Write( actualMap );

             Assert.AreEqual( expectedWidth, actualMap.Width );
             Assert.AreEqual( expectedHeight, actualMap.Height );
             Assert.AreEqual( expectedMapRepresentation.Replace( " ", string.Empty ), actualMap.ToString() );
        }
Beispiel #4
0
        public void Create_MapCreatedWithCaveCreationStrategy_ExpectedMap()
        {
            int expectedWidth = 50;
             int expectedHeight = 20;
             IRandom random = new DotNetRandom( 27 );
             IMapCreationStrategy<Map> mapCreationStrategy = new CaveMapCreationStrategy<Map>( expectedWidth, expectedHeight, 45, 3, 2, random );
             string expectedMapRepresentation = @"##################################################
                                              ########...###################.#.#####....########
                                              ######.......##############......#####....########
                                              ####........###############......####......#######
                                              ###.........#################...######........####
                                              ##........#################.##..#####.....########
                                              ###.......#######.#.######..##..#######.#..#######
                                              ####......######.......#........#########..#######
                                              #####.......#....##....###......#########..#######
                                              ######........#####..............#########..######
                                              #..###......########....######...#########..######
                                              #...##......########.....#####.....#.######..#####
                                              #............##########..######......######..#####
                                              #...........########.....######.#....#######..####
                                              ##...........#######.....###################..####
                                              #............#.#####........#################..###
                                              ##.............#####................#########..###
                                              ###.............#####........######...........####
                                              ####.#....#.#.#######.#.#...######################
                                              ##################################################";

             IMap actualMap = Map.Create( mapCreationStrategy );
             Trace.Write( actualMap );

             Assert.AreEqual( expectedWidth, actualMap.Width );
             Assert.AreEqual( expectedHeight, actualMap.Height );
             Assert.AreEqual( expectedMapRepresentation.Replace( " ", string.Empty ), actualMap.ToString() );
        }