Beispiel #1
0
        public void drawMaze(MazeField origin, int mazeHeight, int mazeWidth)
        {
            MazeField field = origin;

            for (int y = 0; y < mazeHeight; y++)
            {
                for (int x = 0; x < mazeWidth; x++)
                {
                    try
                    {
                        Console.Write(field.symbol);
                        field = field._east;
                    }
                    catch
                    {
                        Console.Write(' ');
                        break;
                    }
                }
                Console.WriteLine();

                origin = origin._south;
                field  = origin;
            }
        }
Beispiel #2
0
        public List <MazeField> Find(TwoDMaze maze)
        {
            var shortestPath = new ShortestPath <MazeField>();

            MazeField start = null, end = null;

            foreach (var mazeField in maze.Fields)
            {
                if (mazeField.FieldType == FieldType.Start)
                {
                    start = mazeField;
                }
                if (mazeField.FieldType == FieldType.End)
                {
                    end = mazeField;
                }
            }

            var graph = BuildGraphFromMaze(maze);

            var startGraphNode = graph.Vertices.First(v => v.Value == start);
            var endGraphNode   = graph.Vertices.First(v => v.Value == end);

            var shortestGraphPath = shortestPath.FindPath(graph, startGraphNode, endGraphNode);

            return(shortestGraphPath.Select(p => p.Value).ToList());
        }
Beispiel #3
0
        public virtual bool move(Directions d)
        {
            if (checkMove(d))
            {
                this.cur_spot.content = null;
                this.cur_spot         = cur_spot.findNextField(d);
                if (check)
                {
                    this.cur_spot.content = this;
                    return(true);
                }
            }

            return(false);
        }
Beispiel #4
0
        private static void UpdateField(MazeField field, QTable qtable, State state)
        {
            var qCells = qtable.Cells.Where(f => f.State.Column == field.Column && f.State.Row == field.Row);

            var rect = _canvas.Children.OfType <Rectangle>().Single(f => f.Tag == field);

            rect.Fill = MapBrush(field, state);

            var dp         = _canvas.Children.OfType <DockPanel>().Single(f => f.Tag == field);
            var textBlocks = dp.Children.OfType <TextBlock>();

            foreach (var txb in textBlocks)
            {
                var action = (Domain.Models.Action)txb.Tag;
                var qValue = Math.Round(qCells.Single(f => f.Action == action).QValue, 2).ToString(CultureInfo.InvariantCulture);
                txb.Text = qValue;
            }
        }
        private void MenuItemSaveImage_Click(object sender, RoutedEventArgs e)
        {
            if (isSizeChanged)
            {
                isSizeChanged = false;
                maze.Reset();
            }
            maze.MakeMaze();
            var filePicker = new System.Windows.Forms.SaveFileDialog();

            filePicker.Filter = "PNG files|*.png|All Files|*.*";
            filePicker.Title  = "Save diagram as PNG";
            if (filePicker.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                SaveUsingEncoder(filePicker.FileName, MazeField, new PngBitmapEncoder());
                MazeField.UpdateLayout();
            }
            maze.MakeMaze();
        }
Beispiel #6
0
        private static void CreateField(MazeField field, Canvas canvas)
        {
            const int FieldSize = 60;

            var rectangle = new Rectangle
            {
                Height = FieldSize,
                Width  = FieldSize,
                Tag    = field
            };

            var blackBrush = new SolidColorBrush
            {
                Color = Colors.Black
            };

            var dp = new DockPanel
            {
                LastChildFill = false,
                Width         = FieldSize,
                Height        = FieldSize,
                Tag           = field,
            };

            AppendTextBlock(dp, Action.Down);
            AppendTextBlock(dp, Action.Up);
            AppendTextBlock(dp, Action.Left);
            AppendTextBlock(dp, Action.Right);

            Canvas.SetLeft(dp, field.Column * FieldSize);
            Canvas.SetTop(dp, field.Row * FieldSize);
            Panel.SetZIndex(dp, 3);

            Canvas.SetLeft(rectangle, field.Column * FieldSize);
            Canvas.SetTop(rectangle, field.Row * FieldSize);

            rectangle.StrokeThickness = 1;
            rectangle.Stroke          = blackBrush;

            canvas.Children.Add(dp);
            canvas.Children.Add(rectangle);
        }
Beispiel #7
0
        private static Brush MapBrush(MazeField field, State state)
        {
            if (field.IsWinningPoint)
            {
                return(new SolidColorBrush
                {
                    Color = Colors.Red
                });
            }

            if (field.Column == state.Column && field.Row == state.Row)
            {
                return(new SolidColorBrush
                {
                    Color = Colors.Yellow
                });
            }

            return(new SolidColorBrush
            {
                Color = Colors.LightBlue
            });
        }
 private void Awake()
 {
     field = gameObject.GetComponent <MazeField>();
 }
Beispiel #9
0
 public Player(MazeField start)
 {
     this.cur_spot = start;
     this.symbol   = '@';
 }
Beispiel #10
0
 public Crate(MazeField location)
 {
     this.cur_spot = location;
     this.symbol   = '#';
 }
Beispiel #11
0
 public Employee(MazeField start)
 {
     this.cur_spot = start;
     this.symbol   = '$';
     this.awake    = true;
 }