示例#1
0
 public void SetMarkerAtTest()
 {
     Tile t = new Tile(0, 0);
     t.SetMarkerAt(Direction.Right, 123);
     Assert.IsTrue(t.HasMarkerAt(Direction.Right));
     Assert.AreEqual(123, t.MarkerAt(Direction.Right));
 }
示例#2
0
 public void SetGetTest()
 {
     Tile expected = new Tile(2, 2, 654);
     Map.AddTile(expected);
     Assert.AreEqual(expected, Map.TileAt(2, 2));
 }
示例#3
0
 public void SetWallAtTest()
 {
     Tile t = new Tile(0, 0);
     t.SetWallAt(Direction.Left, true);
     Assert.IsTrue(t.HasWallAt(Direction.Left));
 }
示例#4
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="map"></param>
        /// <param name="tile"></param>
        /// <param name="target"></param>
        /// <returns></returns>
        private static RouteEntry NextEntry(Map map, Tile tile, Direction target)
        {
            int distance = 0;
            while (true)
            {
                // Get next tile in direction.
                int x = tile.X + (target == Direction.Left ? -1 : target == Direction.Right ? 1 : 0);
                int y = tile.Y + (target == Direction.Up ? -1 : target == Direction.Down ? 1 : 0);

                // If we reached the outskirts and found no marker, this is an unplannable route.
                if (!map.WithinBorders(x, y))
                    return null;

                distance++;
                tile = map.TileAt(x, y);

                // Found a marker? Great. Plan it.
                if (tile.HasMarkerAt(target))
                {
                    return new RouteEntry(target, tile.MarkerAt(target), distance, distance - 1);
                }

                // If there is a wall but no marker, this is an unplannable route.
                if (tile.HasWallAt(target))
                    return null;
            }
        }
示例#5
0
 /// <summary>
 /// Set the wall status of the tiles next to the current tile.
 /// </summary>
 /// <param name="direction">The direction the wall is in</param>
 /// <param name="tiles">The tiles</param>
 /// <param name="x">The current tile's x position</param>
 /// <param name="y">The current tile's y position</param>
 /// <param name="truth">A boolean indicating if there is a wall or not</param>
 private static void SetAdjointWalls(Direction direction, Tile[,] tiles, int x, int y, bool truth)
 {
     int height = tiles.GetLength(0);
     int width = tiles.GetLength(1);
     if (direction == Direction.Left && x > 0)
         tiles[y, x - 1].SetWallAt(Direction.Right, truth);
     else if (direction == Direction.Right && x < width - 1)
         tiles[y, x + 1].SetWallAt(Direction.Left, truth);
     else if (direction == Direction.Up && y > 0)
         tiles[y - 1, x].SetWallAt(Direction.Down, truth);
     else if (direction == Direction.Down && y < height - 1)
         tiles[y + 1, x].SetWallAt(Direction.Up, truth);
 }
示例#6
0
 /// <summary>
 /// initialize the Tiles for the created map.
 /// </summary>
 /// <param name="width"></param>
 /// <param name="height"></param>
 /// <returns></returns>
 private static Tile[,] CreateTiles(int width, int height)
 {
     Tile[,] tiles = new Tile[height, width];
     for (int i = 0; i < height; i++)
         for (int j = 0; j < width; j++)
             tiles[i, j] = new Tile(j, i);
     return tiles;
 }