Пример #1
0
 /// <summary>
 /// 
 /// </summary>
 protected Timeout MoveToCell(Cell from, Cell to)
 {
     // We compute move time and we check if it is a valid number.
     var time = TimeUnit / Speed;
     Debug.Assert(!double.IsNaN(time) && !double.IsInfinity(time));
     // At last, a timeout event is created and returned.
     return _env.Timeout(time);
 }
Пример #2
0
 public Maze(uint width, uint height)
 {
     Debug.Assert(width > 0 && height > 0);
     Width = width;
     Height = height;
     Cells = AllocateCells();          
     GenerateMaze();
     // At last, we create entrance and exit.
     Entrance = Cells[0, 0];
     Exit = Cells[height - 1, width - 1];
 }
Пример #3
0
 public void MoveEscaper(EscaperBase escaper, Cell cell)
 {
     Action<EscaperBase, Cell> me = _mainPage.MazeCanvas.MoveEscaper;
     _mainPage.Dispatcher.BeginInvoke(me, escaper, cell);
 }
Пример #4
0
 Cell[,] AllocateCells()
 {
     // We need to allocate one more row/column,
     // in order to efficiently handle walls and borders.
     var allocWidth = Width + 1;
     var allocHeight = Height + 1;
     // Maze cells are allocated using new measures.
     var cells = new Cell[allocHeight, allocWidth];
     for (var h = 0U; h < allocHeight; ++h) {
         for (var w = 0U; w < allocWidth; ++w) {
             cells[h, w] = new Cell(this, w, h);
         }
     }
     return cells;
 }
Пример #5
0
 protected override Cell ChooseNextCell(Cell actual)
 {
     return actual;
 }
Пример #6
0
 /// <summary>
 /// 
 /// </summary>
 protected abstract Cell ChooseNextCell(Cell actual);
Пример #7
0
 protected override Cell ChooseNextCell(Cell actual)
 {
     if (actual.X <= 10)
     return actual.GetNeighbour(WallPosition.East);
     return actual;
 }
Пример #8
0
        void PositionEscaperInsideCell(Shape figure, Cell cell)
        {
            // Cell dimensions are computed from canvas size.
            var cellWidth = Canvas.ActualWidth / _currentMaze.Width;
            var cellHeight = Canvas.ActualHeight / _currentMaze.Height;

            // Useful methods to compute cell offsets.
            Func<uint, double> xOffset = x => x * cellWidth;
            Func<uint, double> yOffset = y => y * cellHeight;

            figure.Fill = new SolidColorBrush(Colors.Magenta);
            figure.SetValue(Canvas.LeftProperty, xOffset(cell.X));
            figure.SetValue(Canvas.TopProperty, yOffset(cell.Y));
            figure.Width = figure.Height = 15;
        }
Пример #9
0
 public void MoveEscaper(EscaperBase escaper, Cell cell)
 {
     PositionEscaperInsideCell(_escapers[escaper], cell);
     Canvas.UpdateLayout();
 }