Example #1
0
        private void PianoView_KeyPress(object sender, KeyPressEventArgs e)
        {
            switch (e.KeyChar)
            {
            case 'A':
            case 'a':
                press = '0';
                System.Console.Beep(sound[5] / 2, 200);
                break;

            case 'S':
            case 's':
                press = '1';
                System.Console.Beep(sound[6] / 2, 200);
                break;

            case 'D':
            case 'd':
                press = '2';
                System.Console.Beep(sound[0], 200);
                break;

            case 'F':
            case 'f':
                press = '3';
                System.Console.Beep(sound[1], 200);
                break;

            case 'G':
            case 'g':
                press = '4';
                System.Console.Beep(sound[2], 200);
                break;

            case 'H':
            case 'h':
                press = '5';
                System.Console.Beep(sound[3], 200);
                break;

            case 'J':
            case 'j':
                press = '6';
                System.Console.Beep(sound[4], 200);
                break;

            case 'K':
            case 'k':
                press = '7';
                System.Console.Beep(sound[5], 200);
                break;

            case 'L':
            case 'l':
                press = '8';
                System.Console.Beep(sound[6], 200);
                break;

            case ';':
            case ':':
                press = '9';
                System.Console.Beep(sound[0] * 2, 200);
                break;

            default:
                break;
            }

            if (press == bee[count])
            {
                count++;
                if (count == 24)
                {
                    //遊戲結束
                    Finish finish = new Finish();
                    finish.BackGround(0);
                    finish.FormClosed += new FormClosedEventHandler(view_FormClosed); //當pianoview關閉時,返回主畫面
                    finish.Show();
                    this.Hide();
                }
            }
            else
            {
                count = 0;
            }
        }