Esempio n. 1
0
        static void Main(string[] args)
        {
            HallsMap map = new HallsMap();

            Console.WriteLine(map.ToString());
            Console.WriteLine("Write something to find a Path (type 'exit' to quit)");
            while (Console.ReadLine() != "exit")
            {
                IteratableTile startTile = map.getStart();
                var            path      = startTile.Path;
                foreach (var tile in path)
                {
                    Console.WriteLine(tile);
                    //todo improve visual outpu
                }
            }
        }
Esempio n. 2
0
        private IEnumerable <String> Traverse(IteratableTile current, List <MapTile> parents)
        {
            if (parents.Contains(current.tile))
            {
                yield break;
            }
            parents.Add(current.tile);

            yield return(current.tile.ToString());

            foreach (var direction in current.tile.Exits)
            {
                foreach (var v in Traverse(current.halls.GeTileByNeighbour(current, direction), parents))
                {
                    yield return(v);
                }
            }
        }
Esempio n. 3
0
        public IteratableTile GeTileByNeighbour(IteratableTile parent, MapTile.MapTileExits direction)
        {
            MapTile tile     = parent.tile;
            MapTile nextTile = null;

            for (int j = 0; j < tiles.GetLength(0); j++)     //Vertical
            {
                for (int k = 0; k < tiles.GetLength(1); k++) //Horizontal
                {
                    if (tiles[j, k] == tile)
                    {
                        MapTile north = (j == 0) ? tiles[tiles.GetLength(0) - 1, k] : tiles[j - 1, k];
                        MapTile east  = (k == tiles.GetLength(1) - 1) ? tiles[j, 0] : tiles[j, k + 1];
                        MapTile west  = (k == 0) ? tiles[j, tiles.GetLength(1) - 1] : tiles[j, k - 1];
                        MapTile south = (j == tiles.GetLength(0) - 1) ? tiles[0, k] : tiles[j + 1, k];

                        switch (direction)
                        {
                        case MapTile.MapTileExits.East:
                            nextTile = east;
                            break;

                        case MapTile.MapTileExits.North:
                            nextTile = north;
                            break;

                        case MapTile.MapTileExits.South:
                            nextTile = south;
                            break;

                        default:         //West
                            nextTile = west;
                            break;
                        }
                    }
                }
            }
            return(new IteratableTile(nextTile, this, tile));
        }