private void btnSaveMap_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFile = new SaveFileDialog();

            saveFile.AddExtension = true;
            saveFile.DefaultExt   = "map";
            saveFile.Filter       = "Map files (*.map)|*.map";

            if (saveFile.ShowDialog() == DialogResult.OK)
            {
                Map map = new Map();
                map.Name      = Path.GetFileName(saveFile.FileName);
                map.MapWidth  = MapWidth;
                map.MapHeight = MapHeight;

                foreach (Panel p in Controls.OfType <Panel>())
                {
                    map.AddTile((MapTile)p.Tag);
                }

                map.SaveMapToFile(saveFile.FileName);
            }
        }
Beispiel #2
0
        private void button3_Click(object sender, EventArgs e)
        {
            List <string> alarms_for_delete = new List <string>();
            int           number_for_delete = 0;

            foreach (var ch in Controls.OfType <CheckBox>())
            {
                if (ch.Checked)
                {
                    number_for_delete++;
                    for (int i = 0; i < alarm.Count; i++)
                    {
                        if (alarm[Convert.ToInt32(Convert.ToString(ch.Name[8])) - number_for_delete] == alarm[i])
                        {
                            alarm.RemoveAt(i);
                        }
                    }
                    alarms_for_delete.Add(ch.Name);
                }
            }
            if (number_for_delete != 0)
            {
                foreach (var ch in Controls.OfType <CheckBox>())
                {
                    if (ch.Checked)
                    {
                        foreach (var lb in Controls.OfType <Label>())
                        {
                            if (Convert.ToInt32(Convert.ToString(lb.Name[5])) > 0)
                            {
                                lb.Visible = false;
                            }
                        }
                        foreach (var che in Controls.OfType <CheckBox>())
                        {
                            che.Checked = false;
                            che.Visible = false;
                        }
                        break;
                    }
                }
                for (int i = 0; i < alarm.Count; i++)
                {
                    foreach (var lb in Controls.OfType <Label>())
                    {
                        if (Convert.ToInt32(Convert.ToString(lb.Name[5])) == (i + 2))
                        {
                            lb.Text    = alarm[i];
                            lb.Visible = true;
                        }
                    }
                    foreach (var ch in Controls.OfType <CheckBox>())
                    {
                        if (Convert.ToInt32(Convert.ToString(ch.Name[8])) == (i + 1))
                        {
                            ch.Visible = true;
                        }
                    }
                }
                numbers_of_alarms -= number_for_delete;
            }
            else
            {
                MessageBox.Show("Не выбран ни один будильник для удаления");
            }
        }
Beispiel #3
0
        private void AddAll_Click(object sender, EventArgs e)
        {
            bool flag = false;

            foreach (CheckBox x in Controls.OfType <CheckBox>())
            {
                if (x.Checked)
                {
                    flag = true;
                    break;
                }
            }
            foreach (RadioButton x in ControlPanel.Controls.OfType <RadioButton>())
            {
                if (x.Checked)
                {
                    flag = true;
                    break;
                }
            }
            //foreach (TextBox x in Controls.OfType<TextBox>())
            //    if (x.Text == "")
            //    {
            //        flag = false;
            //        break;
            //    }
            int buf;

            if (!flag ||
                DisciplineName.Text == "Название дисциплины" ||
                SemestrValue.Text == "" ||
                SNP.Text == "Ф.И.О" ||
                Pulpit.Text == "Кафедра" ||
                books.Count == 0 || LecturesCountValue.Text == "" ||
                LabsCountValue.Text == "" ||
                int.Parse(SemestrValue.Text) > 6)
            {
                MessageBox.Show("Некорректно введены данные");
            }
            else
            {
                discipline = new Discipline(DisciplineName.Text,
                                            int.Parse(SemestrValue.Text), (int)CourseValue.Value,
                                            new Spec(SpecializationPOIT.Checked, SpecializationPOIBMS.Checked,
                                                     SpecializationISIT.Checked, SpecializationDEVI.Checked),
                                            LecturesCount.Value, LabsCount.Value, ((exam.Checked) ? PassType.Exam : PassType.Test),
                                            new Lector(SNP.Text, Pulpit.Text, (int)NumberAudit.Value, (int)CorpusAydit.Value), books);


                var results = new List <ValidationResult>();
                var context = new ValidationContext(discipline);
                if (!Validator.TryValidateObject(discipline, context, results, true))
                {
                    foreach (var error in results)
                    {
                        string strWithErrroe = error.ErrorMessage;
                        MessageBox.Show(strWithErrroe);
                    }
                    return;
                }

                try
                {
                    DataContractJsonSerializer Serializer = new DataContractJsonSerializer(typeof(List <Discipline>));
                    using (FileStream File = new FileStream("Serialize.json", FileMode.Open))
                    {
                        disciplines = (List <Discipline>)Serializer.ReadObject(File);
                    }
                }
                catch { }
                disciplines.Add(discipline);
                DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(List <Discipline>));
                using (FileStream file = new FileStream("Serialize.json", FileMode.OpenOrCreate))
                {
                    serializer.WriteObject(file, disciplines);
                }
                disciplines.Clear();
                BookList.Items.Clear();
                books.Clear();
                CountOfObject.Text = countObj().ToString();
                LastAction.Text    = "Добавление дисциплины";
            }
        }
Beispiel #4
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            for (int i = tail_count; i > 0; i--)
            {
                foreach (PictureBox item in Controls.OfType <PictureBox>())
                {
                    /*
                     * //šablona
                     * if (item.Tag.ToString() == tail_count.ToString())
                     * {
                     *  item.Location = new Point(pictureBox1.Location.X,pictureBox1.Location.Y);
                     * }
                     */
                    if (item.Tag.ToString() == i.ToString())
                    {
                        foreach (PictureBox item2 in Controls.OfType <PictureBox>())
                        {
                            if (item2.Tag.ToString() == (i + 1).ToString())
                            {
                                item2.Location = new Point(item.Location.X, item.Location.Y);
                            }
                        }
                    }
                }
            }

            if (direction == 0)
            {
                if (pictureBox1.Location.X == 0)
                {
                    pictureBox1.Location = new Point(pictureBox1.Location.X + 400, pictureBox1.Location.Y);
                }
                else
                {
                    pictureBox1.Location = new Point(pictureBox1.Location.X - 25, pictureBox1.Location.Y);
                }
            }
            if (direction == 1)
            {
                if (pictureBox1.Location.Y == 400)
                {
                    pictureBox1.Location = new Point(pictureBox1.Location.X, pictureBox1.Location.Y - 400);
                }
                else
                {
                    pictureBox1.Location = new Point(pictureBox1.Location.X, pictureBox1.Location.Y + 25);
                }
            }
            if (direction == 2)
            {
                if (pictureBox1.Location.X == 400)
                {
                    pictureBox1.Location = new Point(pictureBox1.Location.X - 400, pictureBox1.Location.Y);
                }
                else
                {
                    pictureBox1.Location = new Point(pictureBox1.Location.X + 25, pictureBox1.Location.Y);
                }
            }
            if (direction == 3)
            {
                if (pictureBox1.Location.Y == 0)
                {
                    pictureBox1.Location = new Point(pictureBox1.Location.X, pictureBox1.Location.Y + 400);
                }
                else
                {
                    pictureBox1.Location = new Point(pictureBox1.Location.X, pictureBox1.Location.Y - 25);
                }
            }

            foreach (PictureBox item in Controls.OfType <PictureBox>())
            {
                if (item.Tag != null && item.Tag.ToString() != "food" && item.Tag.ToString() != "1")
                {
                    if (pictureBox1.Location == item.Location)
                    {
                        timer1.Stop();
                        MessageBox.Show("You Lost! Score " + tail_count + "!");
                        Application.Exit();
                    }
                }
            }


            foreach (PictureBox item in Controls.OfType <PictureBox>())
            {
                if (item.Tag == "food")
                {
                    if (item.Location == pictureBox1.Location)
                    {
                        add_tail(item.Location.X, item.Location.Y);
                        Controls.Remove(item);
                        spawn();
                    }
                }
            }



            can_use_keys = true;
        }