Example #1
0
        private void OpenMenuItemClick(object sender, System.EventArgs e)
        {
            if (!SaveIfHasChanged())
            {
                return;
            }

            var dialogWnd = new OpenFileWindow {
                TargetFolder = targetMapFolder
            };

            if (dialogWnd.ShowDialog() == DialogResult.OK)
            {
                string[] mazeString;
                try
                {
                    mazeString = File.ReadAllLines(dialogWnd.FileName);
                }
                catch (Exception exception)
                {
                    MessageBox.ShowError(exception.Message);
                    return;
                }

                rowCount = mazeString.Length;
                colCount = mazeString[0].Length;

                var mazeCells = new int[rowCount, colCount];
                for (var rowIndex = 0; rowIndex < rowCount; rowIndex++)
                {
                    for (var colIndex = 0; colIndex < colCount; colIndex++)
                    {
                        var mazeCellValue = Convert.ToInt32(mazeString[rowIndex][colIndex].ToString());
                        mazeCells[rowIndex, colIndex] = mazeCellValue;
                        if (mazeCellValue == (int)MapItem.StartPoint)
                        {
                            startPoint = new Point(colIndex, rowIndex);
                        }

                        if (mazeCellValue == (int)MapItem.EndPoint)
                        {
                            endPoint = new Point(colIndex, rowIndex);
                        }
                    }
                }

                var mapWnd = new MapViewerWindow(mazeCells)
                {
                    panel1 = { Parent = panel1 }
                };
                PrepareStatusBar(new Size(colCount, rowCount));
                MapViewerWindowPrepare(mapWnd);
                fileName = Path.GetFileNameWithoutExtension(dialogWnd.FileName);
                SetWindowTitle();
            }
        }
Example #2
0
 private void MapViewerWindowPrepare(MapViewerWindow targetWnd)
 {
     if (currentMapWnd != null)
     {
         OnKeyPressed -= currentMapWnd.KeyPressedHandler;
         currentMapWnd.OnCursorChanged -= CurrentMapWndCursorChanged;
         currentMapWnd.OnMapChanged    -= CurrentMapChanged;
     }
     currentMapWnd = targetWnd;
     currentMapWnd.CurrentMapItem = MapItem.Wall;
     OnKeyPressed += currentMapWnd.KeyPressedHandler;
     currentMapWnd.OnCursorChanged += CurrentMapWndCursorChanged;
     currentMapWnd.OnMapChanged    += CurrentMapChanged;
     SetSaveEnabled();
 }
Example #3
0
        private void GenerateClick(object sender, EventArgs e)
        {
            if (!SaveIfHasChanged())
            {
                return;
            }
            var dimension = new Size(colCount, rowCount);
            var mapWnd    = new MapViewerWindow(CreateMaze(dimension))
            {
                panel1 = { Parent = this.panel1 }
            };

            PrepareStatusBar(dimension);
            MapViewerWindowPrepare(mapWnd);
        }
Example #4
0
        private void ClearMazeClick(object sender, EventArgs e)
        {
            if (hasChanged && MessageBox.Show("Clear map", "Do you want to clear current map", MessageBoxIcon.Question, MessageBoxButtons.YesNo) == DialogResult.No)
            {
                return;
            }

            var dimension = new Size(colCount, rowCount);
            var mapWnd    = new MapViewerWindow(CreateEmptyMaze(dimension))
            {
                panel1 = { Parent = this.panel1 }
            };

            PrepareStatusBar(dimension);
            MapViewerWindowPrepare(mapWnd);
        }
Example #5
0
        private void NewMenuItemClick(object sender, System.EventArgs e)
        {
            if (!SaveIfHasChanged())
            {
                return;
            }

            var dialogWnd = new MazeDimensionWindow();

            if (dialogWnd.ShowDialog() == DialogResult.OK)
            {
                startPoint = Point.Empty;
                endPoint   = null;
                var mapWnd = new MapViewerWindow(CreateEmptyMaze(dialogWnd.SelectedDimension));
                mapWnd.panel1.Parent = this.panel1;
                PrepareStatusBar(dialogWnd.SelectedDimension);
                MapViewerWindowPrepare(mapWnd);
            }
        }