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";
            }
        }