Exemplo n.º 1
0
        private static void RunOptionsAndReturnExitCode(Options opts)
        {
            if (opts.DoLog)
            {
                ConfigureLog4Net();
            }

            try
            {
                using (FileStream fs = new FileStream(opts.JsonPath, FileMode.Open))
                {
                    using (StreamReader sr = new StreamReader(fs))
                    {
                        string json = sr.ReadToEnd();
                        Puzzle = JsonConvert.DeserializeObject <PicrossPuzzle>(json);
                        Console.WriteLine($"Loaded puzzle from {fs.Name}");
                    }
                }
            }
            catch (Exception)
            {
                Console.WriteLine("Error while opening json");
            }

            Board = new PicrossBoard(Puzzle);
            Console.WriteLine("Board loaded, next is solving...");
            Board.Solve(verboseLevel: opts.Verbose);
            Console.WriteLine("Solving complete, result:");
            Console.Write(Board.Print());

            if (!opts.NoWait)
            {
                PressEnterToContinue();
            }
        }
Exemplo n.º 2
0
        private void Load_OnClick(object sender, RoutedEventArgs e)
        {
            PicrossPuzzle puzzle = null;

            try
            {
                using (FileStream fs = new FileStream(JsonPath.Text, FileMode.Open))
                {
                    using (StreamReader sr = new StreamReader(fs))
                    {
                        string json = sr.ReadToEnd();
                        puzzle = JsonConvert.DeserializeObject <PicrossPuzzle>(json);
                    }
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Error while opening json");
            }

            if (puzzle != null)
            {
                BoardView.Puzzle = puzzle;
            }
        }
Exemplo n.º 3
0
 public void LoadFromJson_Solve(string puzzlePath)
 {
     using (FileStream fs = new FileStream(puzzlePath, FileMode.Open))
     {
         using (StreamReader sr = new StreamReader(fs))
         {
             string        json   = sr.ReadToEnd();
             PicrossPuzzle puzzle = JsonConvert.DeserializeObject <PicrossPuzzle>(json);
             PicrossBoard  board  = new PicrossBoard(puzzle);
             board.Solve();
             Assert.True(board.IsSolved);
         }
     }
 }