Esempio n. 1
0
 /// <summary>
 /// Event handler that gets called when a nonogram text file gets dropped.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void Grid_Drop(object sender, DragEventArgs e)
 {
     if (_running)
     {
         return;
     }
     if (!e.Data.GetDataPresent(DataFormats.FileDrop))
     {
         return;
     }
     _running = true;
     try
     {
         Nonogram ng = NonoGramFactory.ParseFromFile(((DataObject)e.Data).GetFileDropList()[0]);
         MakeGrid(ng);
         stateBox.Text = "Solving...";
         _solveBW.RunWorkerAsync(ng);
     }
     catch (ArgumentException ex)
     {
         stateBox.Text = ex.Message;
         _running      = false;
     }
     catch (Exception)
     {
         stateBox.Text = "Unexpected exception while solving";
         _running      = false;
     }
     e.Handled = true;
 }
Esempio n. 2
0
        // Konstruktor
        public MainWindow()
        {
            InitializeComponent();
            // Wartości początkowe
            Game    = new Nonogram();
            Solving = false;

            // Stworzenie nowe Timera i przypisanie mu metodi i interwału
            SolvingInterval          = new Timer();
            SolvingInterval.Tick    += new EventHandler(NextSolveStage);
            SolvingInterval.Interval = 1;
        }
Esempio n. 3
0
        private void DrawNonogram(int contentIndex, Nonogram n, bool addHandler, TimeSpan elapsed)
        {
            var scrollView   = this.Content as ScrollViewer;
            var contentPanel = scrollView.Content as Panel;
            var stackPanel   = contentPanel.Children[contentIndex] as Panel;
            var nonogramView = stackPanel.Children[0] as NonogramView;
            var timeTxtBlck  = stackPanel.Children[stackPanel.Children.Count - 2] as TextBlock;
            var textBlock    = stackPanel.Children[stackPanel.Children.Count - 1] as TextBlock;

            nonogramView.Nonogram = n;
            timeTxtBlck.Text      = $"{(int)elapsed.TotalMilliseconds} ms";
            if (addHandler)
            {
                nonogramView.PropertyChanged += (sender, args) =>
                {
                    var view = sender as NonogramView;
                    UpdateTextBox(view.Nonogram, textBlock);
                };
                UpdateTextBox(n, textBlock);
            }
        }
Esempio n. 4
0
        public MainWindow()
        {
            InitializeComponent();

            var createHandlers = true;

            cts             = new CancellationTokenSource();
            _solvedNonogram = NonogramFactory.MakeNonogram(rows, columns);
            ClearNonograms();
            MakeNonograms(createHandlers);
            this.KeyDown += (o, args) =>
            {
                if (args.Key == Key.Space)
                {
                    cts.Cancel();
                    cts             = null;
                    cts             = new CancellationTokenSource();
                    _solvedNonogram = NonogramFactory.MakeNonogram(rows, columns);
                    ClearNonograms();
                    MakeNonograms(false);
                }
            };
        }
Esempio n. 5
0
        private void UpdateTextBox(Nonogram n, TextBlock blk)
        {
            for (int i = 0; i < n.Height; i++)
            {
                for (int j = 0; j < n.Width; j++)
                {
                    var expected = _solvedNonogram.Cells[i][j].State;
                    var real     = n.Cells[i][j].State;
                    if (Utils.GetRowStatus(n.getRow(i), n.RowDescriptors[i]) == RowStatus.ContainsErrors)
                    {
                        blk.Text = $"found error at: row {i}";
                        return;
                    }

                    if (Utils.GetRowStatus(n.getColumn(j), n.ColumnDescriptors[j]) == RowStatus.ContainsErrors)
                    {
                        blk.Text = $"found error at: col {j}";
                        return;
                    }
                }
            }
            blk.Text = "no errors hooray";
        }
Esempio n. 6
0
        /// <summary>
        /// Sets up a new grid in the window based on the given nonogram
        /// </summary>
        /// <param name="ng">Nonogram to solve</param>
        private void MakeGrid(Nonogram ng)
        {
            wGrid.Children.Clear();
            wGrid.RowDefinitions.Clear();
            wGrid.ColumnDefinitions.Clear();
            GridLength gl = new GridLength(15);

            for (int i = 0; i < ng.Width; i++)
            {
                ColumnDefinition cd = new ColumnDefinition {
                    Width = gl
                };
                wGrid.ColumnDefinitions.Add(cd);
            }

            for (int i = 0; i < ng.Height; i++)
            {
                RowDefinition rd = new RowDefinition {
                    Height = gl
                };
                wGrid.RowDefinitions.Add(rd);
            }
        }
Esempio n. 7
0
        // Tworzenie nowego własnego obrazu
        private void CreateNewNonogram(object sender, EventArgs e)
        {
            // Otwarcie okne tworzenia nowego obrazu
            CreateNonogram NewNonogram = new CreateNonogram();

            NewNonogram.ShowDialog();

            //Sprawdzenie czy został stworzony nowy obraz
            if (NewNonogram.XML != null && NewNonogram.NonogramCreated)
            {
                // Stworzenie nowej gry na podstawie informacji użytkownika
                Game = new Nonogram();
                try
                {
                    Game.LoadNonogramXML(NewNonogram.XML);
                } catch (Exception ex)
                {
                    MessageBox.Show("Wystąpił bład podczas wczytywania pliku:\n" + ex.Message);
                }
                // Sworzenie bitmapy i odblokowywanie przycisków
                CreateBitmap();
            }
        }
Esempio n. 8
0
        // Wczytanie definicji obrazu z pliku
        private void LoadXML(object sender, EventArgs e)
        {
            // Otwarcie dialogu wybierania pliku z filtrem dla plików XML
            OpenFileDialog FileDialog = new OpenFileDialog();

            FileDialog.Filter = "XML | *.xml";
            DialogResult Result = FileDialog.ShowDialog();

            // Sprawdzienie czy wybrano plik i czy jest on typu xml
            if (Result == DialogResult.OK && FileDialog.FileName.Remove(0, FileDialog.FileName.Length - 3).ToLower() == "xml")
            {
                // Stworzenie nowej gey na podstawi wybranego pliku
                Game = new Nonogram();
                try
                {
                    Game.LoadNonogramXML(FileDialog.FileName);
                } catch (Exception ex)
                {
                    MessageBox.Show("Wystąpił bład podczas wczytywania pliku:\n" + ex.Message);
                }
                // Sworzenie bitmapy i odblokowywanie przycisków
                CreateBitmap();
            }
        }