代码如下:
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); } }