小小的钢琴系统

今天学习了Console.Beep()这个方法,然后利用这个方法做了一个小小的钢琴系统,感觉还挺有意思的,下面是主要代码实现:
 while (true)
            {
               
                char i=Console.ReadKey().KeyChar;//输入按键
               
                
                switch (i)
                {
                     
                    case '1':
                        Console.BackgroundColor = ConsoleColor.DarkBlue;   //按键的颜色                    
                        Console.Beep(518,100); //设置  Console.Beep里面的参数,发出  不同的声音,模拟钢琴的八个发音键          
                        break;
                    case '2':
                        Console.Beep(592, 100)
                        Console.BackgroundColor = ConsoleColor.DarkGreen;
                      
                        break;
                    case '3':
                        Console.Beep(666, 100);
                        Console.BackgroundColor = ConsoleColor.DarkRed;
                        break;
                    case '4':
                        Console.Beep(703, 100);
                        Console.BackgroundColor = ConsoleColor.DarkYellow;
                        break;
                    case '5':
                        Console.Beep(777, 100);
                        Console.BackgroundColor = ConsoleColor.DarkMagenta;
                        break;
                    case '6':
                        Console.Beep(851, 100);
                        Console.BackgroundColor = ConsoleColor.DarkCyan;
                        break;
                    case '7':
                        Console.Beep(925, 100);
                        Console.BackgroundColor = ConsoleColor.DarkGray;
                        break;
                    case '8':
                        Console.Beep(1037, 100);
                        Console.BackgroundColor = ConsoleColor.DarkGray;
                        break;
                }
            }
虽然代码很简单,实现的功能也很简单,但是通过学习一个简单的方法,然后能够扩展到别的方面,然后还做出了这么一个小小的系统,感觉还是很不错的,系统还很不完善,以后会继续改进的。

你可能感兴趣的:(职场,系统,休闲,钢琴,小小的)