Ejemplo n.º 1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            comboBox1.Items.AddRange(rate);
            aTimer          = new System.Timers.Timer();
            aTimer.Elapsed += new System.Timers.ElapsedEventHandler(timer1_Tick);

            buttons = new[] { button1, button2, button3, button4 };
            Simon game = new Simon();

            for (int i = 0; i < buttons.Length; i++)
            {
                buttons[i].BackColor = game.Colors[i];
            }
        }
Ejemplo n.º 2
0
        private void button_Click(object sender, EventArgs e)
        {
            comboBox1.Focus();
            Button b = (Button)sender;

            user_sequence.Add(b.BackColor);
            Simon  compare = new Simon();
            string s       = "unknown button";

            aTimer.Interval = 100;
            if (b == button1)
            {
                button1.BackColor = Color.White;
                this.Refresh();
                Delay();
                SoundPlayer redsound = new SoundPlayer(Properties.Resources.tone1);
                redsound.Play();
                button1.BackColor = Color.Red;
                this.Refresh();
            }
            else if (b == button2)
            {
                button2.BackColor = Color.White;
                this.Refresh();
                Delay();
                SoundPlayer greensound = new SoundPlayer(Properties.Resources.tone2);
                greensound.Play();
                button2.BackColor = Color.Green;
                this.Refresh();
            }
            else if (b == button3)
            {
                button3.BackColor = Color.White;
                this.Refresh();
                Delay();
                SoundPlayer bluesound = new SoundPlayer(Properties.Resources.tone3);
                bluesound.Play();
                button3.BackColor = Color.Blue;
                this.Refresh();
            }
            else if (b == button4)
            {
                button4.BackColor = Color.White;
                this.Refresh();
                Delay();
                SoundPlayer yellowsound = new SoundPlayer(Properties.Resources.tone4);
                yellowsound.Play();
                button4.BackColor = Color.Yellow;
                this.Refresh();
            }
            int result = compare.Compare(user_sequence.ToArray(), generator);

            switch (result)
            {
            case 1:
                Console.WriteLine("winner!");
                MessageBox.Show("you won!");
                SoundPlayer winsound = new SoundPlayer(Properties.Resources.win);
                winsound.Play();
                reset();
                break;

            case 0:
                //MessageBox.Show("good job, keep going...");
                Console.WriteLine("good job, keep going...");
                break;

            case -1:
                Console.WriteLine("You lost!");
                SoundPlayer lost = new SoundPlayer(Properties.Resources.lost);
                lost.Play();
                MessageBox.Show("You lost!!!");

                reset();
                break;
            }
        }