Beispiel #1
0
        /// <summary>
        /// Кнопка "OK"
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            int n = 0;

            try
            {
                n = Convert.ToInt32(textBoxSleep.Text);
                if (n < 1 || n > 10)
                {
                    MessageBox.Show("Время подсветки может принимать значения от 1 до 10", "Предупреждение", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                mainForm.sleepTime  = n * 1000;
                mainForm.useRunning = checkBoxUseRunning.Checked;
                SaveSettingsClass           settingsClass = new SaveSettingsClass();
                Dictionary <string, string> settings      = new Dictionary <string, string>();
                settings["sleepTime"]  = "" + mainForm.sleepTime;
                settings["useRunning"] = "" + mainForm.useRunning;
                settingsClass.SaveParameters(settings);
                this.Close();
            }
            catch
            {
                MessageBox.Show("Неправильная запись времени подсветки", "Предупреждение", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Инициализация компонентов и создание поля
        /// </summary>
        public MainForm()
        {
            InitializeComponent();

            openFileDialog1.InitialDirectory = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "Position");
            openFileDialog1.FileName         = "";
            saveFileDialog1.InitialDirectory = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "SavedGames");
            openFileDialog1.FileName         = "";

            SaveSettingsClass           settingsClass = new SaveSettingsClass();
            Dictionary <string, string> settings      = settingsClass.LoadParameters(listOfParameters);

            if (settings.ContainsKey("sleepTime") && !string.IsNullOrEmpty(settings["sleepTime"]))
            {
                sleepTime = Convert.ToInt32(settings["sleepTime"]);
            }
            if (settings.ContainsKey("useRunning") && !string.IsNullOrEmpty(settings["useRunning"]))
            {
                useRunning = Convert.ToBoolean(settings["useRunning"]);
            }

            //
            // Создание игровых панелей и основных меток
            //
            for (int i = 0; i < 9; i++)
            {
                for (int j = 0; j < 9; j++)
                {
                    Panel p = new Panel();
                    p.BackColor         = Color.White;
                    p.BorderStyle       = BorderStyle.FixedSingle;
                    p.Location          = new Point(left + j * 50, top + i * 50);
                    p.Name              = "panel" + i.ToString() + j.ToString();
                    p.Size              = new Size(51, 51);
                    p.TabIndex          = i * 9 + j;
                    p.MouseDoubleClick += new MouseEventHandler(cell_MouseDoubleClick);
                    p.MouseDown        += new MouseEventHandler(cell_MouseClick);

                    Label l = new Label();
                    l.BackColor         = Color.White;
                    l.Font              = new Font("Microsoft Sans Serif", 20.25F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(204)));
                    l.Location          = new Point(11, 8);
                    l.Margin            = new Padding(0);
                    l.Name              = "label" + i.ToString() + j.ToString();
                    l.Size              = new Size(25, 30);
                    l.TabIndex          = 0;
                    l.MouseDoubleClick += new MouseEventHandler(cell_MouseDoubleClick);
                    l.MouseDown        += new MouseEventHandler(cell_MouseClick);
                    p.Controls.Add(l);

                    this.Controls.Add(p);
                    p.BringToFront();
                }
            }

            //
            // Создание горизонтальных разделительных панелей
            //
            for (int i = 0; i < 4; i++)
            {
                Panel p = new Panel();
                p.BackColor = Color.Black;
                p.Location  = new Point(left, top + i * 50 * 3 - 1);
                p.Name      = "splitPanel0" + i;
                p.Size      = new Size(450, 3);
                p.TabIndex  = 0;
                p.TabStop   = true;

                this.Controls.Add(p);
                p.BringToFront();
            }

            //
            // Создание вертикальных разделительных панелей
            //
            for (int j = 0; j < 4; j++)
            {
                Panel p = new Panel();
                p.BackColor = Color.Black;
                p.Location  = new Point(left + j * 50 * 3 - 1, top);
                p.Name      = "splitPanel1" + j;
                p.Size      = new Size(3, 450);
                p.TabIndex  = 0;
                p.TabStop   = true;

                this.Controls.Add(p);
                p.BringToFront();
            }

            //
            // Создание горизонтальных выделительных панелей
            //
            for (int i = 0; i < 2; i++)
            {
                Panel p = new Panel();
                p.BackColor = Color.Red;
                p.Location  = new Point(0, 0);
                p.Size      = new Size(51, 3);
                p.TabIndex  = 0;
                p.TabStop   = true;
                p.Visible   = false;

                if (i == 0)
                {
                    p.Name = "upPanel";
                }
                else
                {
                    p.Name = "downPanel";
                }
                this.Controls.Add(p);
                p.BringToFront();
            }

            //
            // Создание вертикальных выделительных панелей
            //
            for (int j = 0; j < 2; j++)
            {
                Panel p = new Panel();
                p.BackColor = Color.Red;
                p.Location  = new Point(0, 0);
                p.Size      = new Size(3, 51);
                p.TabIndex  = 0;
                p.TabStop   = true;
                p.Visible   = false;
                if (j == 0)
                {
                    p.Name = "leftPanel";
                }
                else
                {
                    p.Name = "rightPanel";
                }
                this.Controls.Add(p);
                p.BringToFront();
            }

            //
            // Инициализация массива с информацией о полях
            //
            currentCell = new CurrentCell();
            cells       = new Cell[9, 9];
            for (int i = 0; i < 9; i++)
            {
                for (int j = 0; j < 9; j++)
                {
                    cells[i, j] = new Cell(this, i, j);
                }
            }
            isPositionSave = true;
        }