Esempio n. 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            // Displays a SaveFileDialog so the user can save the Image
            // assigned to Button2.
            SaveFileDialog saveFileDialog1 = new SaveFileDialog();
            saveFileDialog1.Filter = "Png Image|*.png|Bitmap Image|*.bmp|Gif Image|*.gif";
            saveFileDialog1.Title = "Save an Image File";
            saveFileDialog1.ShowDialog();
            Random gen = new Random();
            SudokuTabla sud;

            Image img= new Bitmap(1020+20,520*(listBox1.SelectedIndex+1)/2);
            Graphics g = Graphics.FromImage(img);
                g.Clear(Color.White);
                g.TextRenderingHint = TextRenderingHint.AntiAlias;
                g.TextContrast = 8;
            List<Image> lista = new List<Image>();
            for (int i = 0; i < listBox1.SelectedIndex + 1; i++) {
                 sud = new SudokuTabla(gen);
                sud.polni();
                sud.prazni();
                Image im= new Bitmap(500, 500);
                SimpleSudoku.draw(sud, im, Color.Black, true);
                g.DrawImageUnscaled(im, 500 * (i % 2)+20, 500 * (i / 2)+20);

            }

                // If the file name is not an empty string open it for saving.
                if (saveFileDialog1.FileName != "")
                {
                    // Saves the Image via a FileStream created by the OpenFile method.
                    System.IO.FileStream fs =
                       (System.IO.FileStream)saveFileDialog1.OpenFile();
                    // Saves the Image in the appropriate ImageFormat based upon the
                    // File type selected in the dialog box.
                    // NOTE that the FilterIndex property is one-based.
                    switch (saveFileDialog1.FilterIndex)
                    {
                        case 1:
                            img.Save(fs,
                             System.Drawing.Imaging.ImageFormat.Png);
                            break;

                        case 2:
                            img.Save(fs,
                               System.Drawing.Imaging.ImageFormat.Bmp);
                            break;

                        case 3:
                            img.Save(fs,
                               System.Drawing.Imaging.ImageFormat.Gif);
                            break;
                    }

                    fs.Close();
                }
        }
Esempio n. 2
0
        public static Image draw(SudokuTabla sud, Image im, Color Fboja, bool ZaPrintanje = false)
        {
            Color    Bboja;
            Graphics g        = Graphics.FromImage(im);
            int      devetina = (im.Width / 9);
            Font     f        = new Font(FontFamily.GenericMonospace, 12);
            Font     fBold    = new Font(FontFamily.GenericSerif, 14, FontStyle.Underline);

            for (int i = 0; i < 9; i++)
            {
                for (int j = 0; j < 9; j++)
                {
                    if ((j) / 3 == 0)
                    {
                        Bboja = Color.FromArgb(10, 20 + 25 * ((j) / 3), 20 + 20 * ((i) / 3));
                    }
                    else if ((j) / 3 == 1)
                    {
                        Bboja = Color.FromArgb(25 * ((j) / 3), 10, 20 * ((i) / 3));
                    }
                    else
                    {
                        Bboja = Color.FromArgb(25 * ((j) / 3), 20 * ((i) / 3), 10);
                    }

                    if (!ZaPrintanje)
                    {
                        if (sud.Workingtabla[i][j] == sud.tablata[i][j] || sud.Workingtabla[i][j] == 0)
                        {
                            g.FillRectangle(new SolidBrush(Bboja), (devetina * j), (devetina * i), devetina - 2, devetina - 2);
                        }
                        else
                        {
                            g.FillRectangle(new SolidBrush(Color.Red), (devetina * j), (devetina * i), devetina - 2, devetina - 2);
                        }
                        g.DrawRectangle(new Pen(Fboja), (devetina * j), (devetina * i), devetina - 2, devetina - 2);
                    }
                    if (ZaPrintanje)
                    {
                        g.DrawRectangle(new Pen(Bboja), (devetina * j), (devetina * i), devetina - 2, devetina - 2);
                    }

                    if (sud.Workingtabla[i][j] != 0 && sud.IspraznetaTabla[i][j] != 0)
                    {
                        g.DrawString((sud.Workingtabla[i][j]).ToString(), fBold, new SolidBrush(Fboja), devetina * j + 10, devetina * i + 10);
                    }
                    else if (sud.Workingtabla[i][j] != 0)
                    {
                        g.DrawString((sud.Workingtabla[i][j]).ToString(), f, new SolidBrush(Fboja), devetina * j + 10, devetina * i + 10);
                    }
                }
            }


            return(im);
        }
Esempio n. 3
0
        private void button6_Click(object sender, EventArgs e)
        {
            Stopped = false;
            Stabla  = new SudokuTabla(gen);
            Stabla.polni();
            Stabla.prazni();
            TimeLabel.Text  = "Time: 0:0";
            button4.Enabled = true;

            Invalidate();
        }
Esempio n. 4
0
        public SimpleSudoku()
        {
            InitializeComponent();



            logo           = Properties.Resources.title;
            pick           = Properties.Resources.picker2;
            timer          = new Timer();
            timer.Interval = 1000;
            timer.Start();
            Score          = null;
            timer.Tick    += new EventHandler(timer_Tick);
            this.BackColor = panel1.BackColor = Color.FromArgb(17, 17, 17);
            back           = Properties.Resources.bac2;
            // panel1.BackColor = Color.Transparent;
            //this.BackColor = panel1.BackColor = Color.Wheat;

            GraphicsImage = new Bitmap(panel1.Width, panel1.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
            //Fills the image we just created with white
            Stabla = new SudokuTabla();
            Stabla.polni();
            Stabla.prazni();
            //   DoubleBuffered = true;
            Graphics.FromImage(GraphicsImage).Clear(this.BackColor);
            panel1.BringToFront();

            GraphicsObject = Graphics.FromImage(GraphicsImage);
            double faktor = 0.15 * (3.0 / 4);

            PicRect = new Rectangle(0, 0, (int)(panel1.Width * 0.15), (int)(panel1.Height * faktor));

            kliknatoI = kliknatoJ = 0;
            KadeX     = 0;
            KadeY     = 0;
            RemainingLabel.ForeColor = TimeLabel.ForeColor = Color.Beige;

            gen       = new Random();
            desetinaY = panel1.Width / 13;
            pocY      = (int)(2.5 * desetinaY);

            desetinaX = panel1.Width / 13;
            pocX      = 2 * desetinaX;
            RemainingLabel.Location = new Point(desetinaX, (int)(1.8 * desetinaY));
            //    GraphicsObject.PageUnit = GraphicsUnit.Millimeter;
        }
Esempio n. 5
0
        public SimpleSudoku()
        {
            InitializeComponent();

            logo = Properties.Resources.title;
            pick = Properties.Resources.picker2;
            timer = new Timer();
            timer.Interval = 1000;
            timer.Start();
            Score = null;
            timer.Tick += new EventHandler(timer_Tick);
            this.BackColor = panel1.BackColor = Color.FromArgb(17,17,17);
            back = Properties.Resources.bac2;
               // panel1.BackColor = Color.Transparent;
            //this.BackColor = panel1.BackColor = Color.Wheat;

            GraphicsImage = new Bitmap(panel1.Width, panel1.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
            //Fills the image we just created with white
            Stabla = new SudokuTabla();
            Stabla.polni();
            Stabla.prazni();
             //   DoubleBuffered = true;
            Graphics.FromImage(GraphicsImage).Clear(this.BackColor);
            panel1.BringToFront();

            GraphicsObject = Graphics.FromImage(GraphicsImage);
            double faktor = 0.15 * (3.0 / 4);
            PicRect = new Rectangle(0, 0, (int)(panel1.Width * 0.15), (int)(panel1.Height * faktor));

            kliknatoI = kliknatoJ = 0;
            KadeX = 0;
            KadeY = 0;
            RemainingLabel.ForeColor =TimeLabel.ForeColor = Color.Beige;

               gen = new Random();
            desetinaY = panel1.Width / 13;
              pocY = (int)(2.5 * desetinaY);

              desetinaX = panel1.Width / 13;
              pocX = 2 * desetinaX;
              RemainingLabel.Location = new Point(desetinaX, (int)(1.8 * desetinaY));
            //    GraphicsObject.PageUnit = GraphicsUnit.Millimeter;
        }
Esempio n. 6
0
        public string ManyTests(int n)
        {
            bool     ff   = true;
            DateTime date = DateTime.Now;
            float    sum  = 0;

            long   pocetno     = (date.Minute * 60000) + (date.Second * 1000) + date.Millisecond;
            Random generatorot = new Random();

            for (int i = 0; i < n; i++)
            {
                SudokuTabla t = new SudokuTabla();
                t.generator = generatorot;
                t.polni();
                t.prazni();
                int vnes = 0;
                for (int j = 0; j < 81; j++)
                {
                    if (t.Workingtabla[j / 9][j % 9] == 0)
                    {
                        vnes++;
                    }
                }
                sum += vnes;
                //         int[] niza = { 1, 2, 4, 6, 7, 89, 1 };
                //           List<int> lniza = niza.ToList();
                //          List<int> lniza2 = new List<int>();
                //            lniza2.AddRange(lniza);
                //              lniza2.Clear();
                ff &= check(t.tablata, t.Trtablata);
                // Console.WriteLine(lniza.Distinct().Count()+"   "+lniza.Count() );
                // Console.ReadKey();
            }
            date = DateTime.Now;


            //Console.WriteLine(ff);
            long krajno = (date.Minute * 60000) + (date.Second * 1000) + date.Millisecond;


            return(string.Format("{0}  {1}  sekundi ,Prosek {2} prazni", ff, ((krajno - pocetno) / n), sum / n));
        }
Esempio n. 7
0
        public static Image draw(SudokuTabla sud, Image im, Color Fboja,bool ZaPrintanje=false)
        {
            Color Bboja;
            Graphics g = Graphics.FromImage(im);
            int devetina = (im.Width / 9) ;
            Font f = new Font(FontFamily.GenericMonospace,12);
            Font fBold = new Font(FontFamily.GenericSerif, 14, FontStyle.Underline);

            for (int i = 0; i < 9; i++)
            {
                for (int j = 0; j < 9; j++)
                {
                    if ((j) / 3 == 0)
                        Bboja = Color.FromArgb(10, 20 + 25 * ((j) / 3), 20 + 20 * ((i) / 3));
                    else if ((j) / 3 == 1)
                        Bboja = Color.FromArgb(25 * ((j) / 3), 10, 20 * ((i) / 3));
                    else
                        Bboja = Color.FromArgb(25 * ((j) / 3), 20 * ((i) / 3), 10);

                    if (!ZaPrintanje)
                    {

                        if (sud.Workingtabla[i][j] == sud.tablata[i][j] || sud.Workingtabla[i][j] == 0)
                            g.FillRectangle(new SolidBrush(Bboja), (devetina * j), (devetina * i), devetina - 2, devetina - 2);
                        else
                        {
                            g.FillRectangle(new SolidBrush(Color.Red), (devetina * j), (devetina * i), devetina - 2, devetina - 2);

                        }
                            g.DrawRectangle(new Pen(Fboja), (devetina * j), (devetina * i), devetina - 2, devetina - 2);
                    }
                    if (ZaPrintanje)
                    g.DrawRectangle(new Pen(Bboja), (devetina * j), (devetina * i), devetina - 2, devetina - 2);

                    if (sud.Workingtabla[i][j] != 0 && sud.IspraznetaTabla[i][j] != 0)
                        g.DrawString((sud.Workingtabla[i][j]).ToString(), fBold, new SolidBrush(Fboja), devetina * j + 10, devetina * i + 10);
                    else if (sud.Workingtabla[i][j] != 0)
                        g.DrawString((sud.Workingtabla[i][j]).ToString(), f, new SolidBrush(Fboja), devetina * j + 10, devetina * i + 10);

                }
            }

            return im;
        }
Esempio n. 8
0
        private void button6_Click(object sender, EventArgs e)
        {
            Stopped = false;
            Stabla = new SudokuTabla(gen);
            Stabla.polni();
            Stabla.prazni();
            TimeLabel.Text = "Time: 0:0";
            button4.Enabled = true;

            Invalidate();
        }
Esempio n. 9
0
        public string ManyTests(int n)
        {
            bool ff = true;
            DateTime date = DateTime.Now;
            float sum = 0;

            long pocetno = (date.Minute * 60000) + (date.Second * 1000) + date.Millisecond;
            Random generatorot = new Random();
            for (int i = 0; i < n; i++)
            {
                SudokuTabla t = new SudokuTabla();
                t.generator = generatorot;
                t.polni();
                t.prazni();
                int vnes = 0;
                for (int j = 0; j < 81; j++)
                    if (t.Workingtabla[j / 9][j % 9] == 0) vnes++;
                sum += vnes;
                //         int[] niza = { 1, 2, 4, 6, 7, 89, 1 };
                //           List<int> lniza = niza.ToList();
                //          List<int> lniza2 = new List<int>();
                //            lniza2.AddRange(lniza);
                //              lniza2.Clear();
                ff &= check(t.tablata, t.Trtablata);
                // Console.WriteLine(lniza.Distinct().Count()+"   "+lniza.Count() );
                // Console.ReadKey();

            }
            date = DateTime.Now;

            //Console.WriteLine(ff);
            long krajno = (date.Minute * 60000) + (date.Second * 1000) + date.Millisecond;

            return string.Format("{0}  {1}  sekundi ,Prosek {2} prazni", ff, ((krajno - pocetno) / n), sum / n);
        }
Esempio n. 10
0
        private void button1_Click(object sender, EventArgs e)
        {
            // Displays a SaveFileDialog so the user can save the Image
            // assigned to Button2.
            SaveFileDialog saveFileDialog1 = new SaveFileDialog();

            saveFileDialog1.Filter = "Png Image|*.png|Bitmap Image|*.bmp|Gif Image|*.gif";
            saveFileDialog1.Title  = "Save an Image File";
            saveFileDialog1.ShowDialog();
            Random      gen = new Random();
            SudokuTabla sud;


            Image    img = new Bitmap(1020 + 20, 520 * (listBox1.SelectedIndex + 1) / 2);
            Graphics g   = Graphics.FromImage(img);

            g.Clear(Color.White);
            g.TextRenderingHint = TextRenderingHint.AntiAlias;
            g.TextContrast      = 8;
            List <Image> lista = new List <Image>();

            for (int i = 0; i < listBox1.SelectedIndex + 1; i++)
            {
                sud = new SudokuTabla(gen);
                sud.polni();
                sud.prazni();
                Image im = new Bitmap(500, 500);
                SimpleSudoku.draw(sud, im, Color.Black, true);
                g.DrawImageUnscaled(im, 500 * (i % 2) + 20, 500 * (i / 2) + 20);
            }


            // If the file name is not an empty string open it for saving.
            if (saveFileDialog1.FileName != "")
            {
                // Saves the Image via a FileStream created by the OpenFile method.
                System.IO.FileStream fs =
                    (System.IO.FileStream)saveFileDialog1.OpenFile();
                // Saves the Image in the appropriate ImageFormat based upon the
                // File type selected in the dialog box.
                // NOTE that the FilterIndex property is one-based.
                switch (saveFileDialog1.FilterIndex)
                {
                case 1:
                    img.Save(fs,
                             System.Drawing.Imaging.ImageFormat.Png);
                    break;

                case 2:
                    img.Save(fs,
                             System.Drawing.Imaging.ImageFormat.Bmp);
                    break;

                case 3:
                    img.Save(fs,
                             System.Drawing.Imaging.ImageFormat.Gif);
                    break;
                }

                fs.Close();
            }
        }