Exemplo n.º 1
0
        private void button0_Click(object sender, EventArgs e)
        {
            int position = Convert.ToInt32(((Button)sender).Tag);

            if (Form3.isMusicNeed)
            {
                playMusic("button.wav");
                sound.Play();
            }
            logic.Moving(position);
            label1.Text = logic.CounterOfMoves(true).ToString();
            Refresh();
            if (logic.gameFinish())
            {
                timer.Stop();
                var result = MessageBox.Show($"EZ PZ!!\n Количество ходов - {label1.Text}\nВаше время - {label4.Text}", "Win!",
                                             MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                if (result == DialogResult.Yes)
                {
                    string name = "";
                    Record person;
                    using (Form5 form5 = new Form5())
                    {
                        if (form5.ShowDialog() == DialogResult.Cancel)
                        {
                            name = Form5.PersonName;
                        }
                        person = new Record(name, Convert.ToInt16(label1.Text), label4.Text, PlayerLevel);
                        personRecord.Add(person);
                    }
                    var a = Serializator.Deserialize <List <Record> >("data.dat");
                    foreach (var item in a)
                    {
                        personRecord.Add(item);
                    }
                    Serializator.Serialize(personRecord, "data.dat");
                    personRecord.Clear();
                }
                tableLayoutPanel1.Enabled = false;
                label1.Text = logic.CounterOfMoves(false).ToString();
                label4.Text = "00:00:00";
            }
            label5.Focus();
        }
Exemplo n.º 2
0
        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            timer.Start();
            if (Form3.isMusicNeed)
            {
                playMusic("keyboard.wav");
                sound.Play();
            }
            label1.Text = logic.CounterOfMoves(true).ToString();
            if (e.KeyCode == Keys.Down)
            {
                int d = positionOfSpace() - 4;
                if (d > 16 || d < 0)
                {
                    d = positionOfSpace();
                }
                else
                {
                    logic.Moving(d);
                }
                Refresh();
            }
            if (e.KeyCode == Keys.Up)
            {
                int d = positionOfSpace() + 4;
                if (d > 16)
                {
                    d = positionOfSpace();
                }
                else
                {
                    logic.Moving(d);
                }
                Refresh();
            }
            if (e.KeyCode == Keys.Left)
            {
                int d = positionOfSpace() + 1;
                if (d > 16 || d < 0)
                {
                    d = positionOfSpace();
                }
                else
                {
                    logic.Moving(d);
                }
                Refresh();
            }
            if (e.KeyCode == Keys.Right)
            {
                int d = positionOfSpace() - 1;
                if (d > 16 || d < 0)
                {
                    d = positionOfSpace();
                }
                else
                {
                    logic.Moving(d);
                }
                Refresh();
            }
            if (logic.gameFinish())
            {
                timer.Stop();
                var result = MessageBox.Show($"EZ PZ!!\n Количество ходов - {label1.Text}\nВаше время - {label4.Text}", "Win!",
                                             MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                if (result == DialogResult.Yes)
                {
                    string name = "";
                    Record person;
                    using (Form5 form5 = new Form5())
                    {
                        if (form5.ShowDialog() == DialogResult.Cancel)
                        {
                            name = Form5.PersonName;
                        }
                        person = new Record(name, Convert.ToInt16(label1.Text), label4.Text, PlayerLevel);
                        personRecord.Add(person);
                    }
                    var a = Serializator.Deserialize <List <Record> >("data.dat");
                    foreach (var item in a)
                    {
                        personRecord.Add(item);
                    }
                    Serializator.Serialize(personRecord, "data.dat");
                    personRecord.Clear();
                }
                tableLayoutPanel1.Enabled = false;

                label1.Text = logic.CounterOfMoves(false).ToString();
                label4.Text = "00:00:00";
            }
        }
Exemplo n.º 3
0
        public void ShowRecordTable()
        {
            var a = Serializator.Deserialize <List <Record> >("data.dat");
            int countX = 0, countY = 0;

            a.Sort(delegate(Record x, Record y)
            {
                if (x.PlayerMoves == 0 && y.PlayerMoves == 0)
                {
                    return(0);
                }
                else if (x.PlayerMoves == 0)
                {
                    return(-1);
                }
                else if (y.PlayerMoves == 0)
                {
                    return(1);
                }
                else
                {
                    return(x.PlayerMoves.CompareTo(y.PlayerMoves));
                }
            });
            Label l1;
            Label l2;
            Label l3;
            Label l4;
            Label l5;

            foreach (var item in a)
            {
                countY++;
                l1      = new Label();
                l2      = new Label();
                l3      = new Label();
                l4      = new Label();
                l5      = new Label();
                l4.Text = countY.ToString();
                if (l4.Text == "1")
                {
                    l4.BackColor = Color.Gold;
                }
                if (l4.Text == "2")
                {
                    l4.BackColor = Color.LightSteelBlue;
                }
                if (l4.Text == "3")
                {
                    l4.BackColor = Color.Peru;
                }
                l4.Font      = new Font(FontFamily.GenericSerif, 12.0F, FontStyle.Regular);
                l4.TextAlign = ContentAlignment.MiddleCenter;
                l1.Text      = item.PlayerName.ToString();
                l1.Font      = new Font(FontFamily.GenericSerif, 12.0F, FontStyle.Underline);
                l1.TextAlign = ContentAlignment.MiddleCenter;
                l2.Text      = item.PlayerMoves.ToString();
                l2.Font      = new Font(FontFamily.GenericSerif, 12.0F, FontStyle.Regular);
                l2.TextAlign = ContentAlignment.MiddleCenter;
                l3.Text      = item.PlayerTime.ToString();
                l3.Font      = new Font(FontFamily.GenericSerif, 12.0F, FontStyle.Regular);
                l3.TextAlign = ContentAlignment.MiddleCenter;
                l5.Text      = item.PlayerLevel.ToString();
                l5.Font      = new Font(FontFamily.GenericSerif, 12.0F, FontStyle.Regular);
                l5.TextAlign = ContentAlignment.MiddleCenter;
                tableLayoutPanel1.Controls.Add(l4, countX, countY);
                tableLayoutPanel1.Controls.Add(l1, ++countX, countY);
                tableLayoutPanel1.Controls.Add(l2, ++countX, countY);
                tableLayoutPanel1.Controls.Add(l3, ++countX, countY);
                tableLayoutPanel1.Controls.Add(l5, ++countX, countY);
                countX = 0;
                tableLayoutPanel1.RowCount = countY;
                tableLayoutPanel1.Refresh();
            }
        }