Loading

C#控制台吹泡泡算法

代码如下:

        static void Main(string[] args)
        {
            Bubbling(100, 100, "O", 1000);
            Console.ReadLine();
        }

        /// <summary>
        /// 冒泡
        /// </summary>
        /// <param name="height">高度</param>
        /// <param name="width">宽度</param>
        /// <param name="type">冒泡形状</param>
        /// <param name="time">冒泡间隔休息时间</param>
        static void Bubbling(int height,int width,string type,int time) 
        {
            List<string> list = new List<string>();
            for (int i = height; i > 0;i-- )
            {
                Console.Clear();
                int ran = new Random().Next(0, width);
                string str = string.Empty;
                for (int j = 0; j < ran; j++) str += " ";
                list.Add(str+ type);
                for (int k = 0; k < i; k++) Console.WriteLine();
                foreach (string item in list) Console.WriteLine(item);
                System.Threading.Thread.Sleep(time);
            }
        }


 

posted @ 2016-01-06 10:27  myEsn2E9  阅读(313)  评论(0编辑  收藏  举报