Exemplo n.º 1
0
        /// <summary>
        /// Подсвечивание неправильных ячеек
        /// </summary>
        /// <param name="errorCells"></param>
        private void ShowErrorCells()
        {
            if (errorCells.Count == 0)
            {
                MenuActionCheck.Enabled = true;
                timerTime.Enabled       = false;
                labelTime.Visible       = labelTimeInfo.Visible = buttonPause.Visible = false;
                currentCell             = new CurrentCell();
                ((Panel)this.Controls["upPanel"]).Visible       = ((Panel)this.Controls["downPanel"]).Visible =
                    ((Panel)this.Controls["leftPanel"]).Visible = ((Panel)this.Controls["rightPanel"]).Visible = false;
                labelInfo.Text = "Данный уровень пройден\r\n\r\nВремя прохождения уровня: " + DateTimeToString(gameTime) + ".";
                typeAction     = TypeAction.none;
                DialogResult dres = MessageBox.Show("Расстановка выполнена верно!\r\nХотите сохранить решённое судоку?", "Поздравление", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                if (dres == DialogResult.Yes)
                {
                    Save_Click(null, null);
                }
                return;
            }

            for (int i = 0; i < errorCells.Count; i++)
            {
                int[] ord = (int[])errorCells[i];
                cells[ord[0], ord[1]].SetCellType(Color.Red);
            }

            timer1.Enabled = true;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Выбор файла с уровнем и начало игры
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonOpen_Click(object sender, EventArgs e)
        {
            if (!SaveByExit())
            {
                return;
            }

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                pathToLevel     = openFileDialog1.FileName;
                labelLevel.Text = Path.GetFileNameWithoutExtension(pathToLevel);

                try
                {
                    LoadLevel();
                }
                catch (Exception ex)
                {
                    currentCell = new CurrentCell();
                    MessageBox.Show("В указанном файле обнаружена ошибка:\r\n\r\n" + ex.ToString(), "Предупреждение", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
            }
        }
Exemplo n.º 3
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;
        }