using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Collections; namespace ZhengYPHappy { class ZhengYPHappy { static void Main(string[] args) { Console.Title = "新年快乐"; ZYPClock clock = new ZYPClock(); TimerCallback tcb = new TimerCallback(clock.PrintDate); Timer t = new Timer(tcb/*回调的委托*/, ""/*参数*/, 0/*第一次执行时间*/, 1000/*间隔执行毫秒数*/); Console.ReadLine(); } } class ZYPClock { private string img = "¤●■〓◆◇◎☆※★"; public ZYPClock() { Console.SetBufferSize(300, 400); Console.SetWindowSize(120, 40); } public int X = 0, Y = 0; //数字样式 public string GroundImg = "※"; public string LeftTop = "※"; public string RightTop = "※"; public string LeftBottom = "※"; public string RightBottom = "※"; // public string GroundSplitStart = "※"; public string GroundSplitEnd = "※"; public string GroundSplit = "※"; //间歇效果 public string GroundPo = "※"; public string[,] str = new string[5, 4]; public void SetGroundString(string img, string po) { GroundImg = img; GroundPo = po; } int tep = 1; int top = 1; public void PrintDate(Object obj) { Console.CursorVisible = false; tep = X; //年 PrintNumber(DateTime.Now.Year / 1000, tep, top); PrintNumber(DateTime.Now.Year / 100 % 10, tep, top); PrintNumber(DateTime.Now.Year / 10 % 10, tep, top); PrintNumber(DateTime.Now.Year % 10, tep, top); PrintSplit(tep, 3, 1); //PrintPoint(DateTime.Now.Second % 10,tep+5, 2, 4,false); //月 PrintNumber(DateTime.Now.Month / 10, tep, top); PrintNumber(DateTime.Now.Month % 10, tep, top); PrintSplit(tep + 1, 3, 1); //PrintPoint(DateTime.Now.Second % 10, tep+5, 2, 4, false); //日 PrintNumber(DateTime.Now.Day / 10, tep, top); PrintNumber(DateTime.Now.Day % 10, tep, top); //=============================================== int l = 1, t = 8; //时 PrintNumber(DateTime.Now.Hour / 10, GetN(ref l), t); PrintNumber(DateTime.Now.Hour % 10, GetN(ref l), t); PrintPoint(DateTime.Now.Second % 10, GetN(ref l) + 5, t + 1, 2, false); //分 PrintNumber(DateTime.Now.Minute / 10, GetN(ref l), t); PrintNumber(DateTime.Now.Minute % 10, GetN(ref l), t); PrintPoint(DateTime.Now.Second % 10, GetN(ref l) + 5, t + 1, 2, false); //秒 PrintNumber(DateTime.Now.Second / 10, GetN(ref l), t); PrintNumber(DateTime.Now.Second % 10, GetN(ref l), t); #region int[][] _ping = new int[10][] { new int[] { }, new int[] { 2,3,4,5,6,7,8}, new int[] { 2,5,8}, new int[] { 3,5,7}, new int[] { 3,5,6}, new int[] { 1,2,4,5,7,8,9}, new int[] { 5}, new int[] { 5}, new int[] { 5}, new int[] { 5}, }; int[][] _ye = new int[10][] { new int[] {7 }, new int[] { 6}, new int[] { 1,2,3,6}, new int[] { 1,3,6,9}, new int[] { 1,3,4,5,6,7,8}, new int[] { 1,3,6}, new int[] { 1,2,3,6}, new int[] { 1,6}, new int[] { 6}, new int[] {}, }; int[][] _zheng = new int[10][] { new int[] { }, new int[] { 2, 4, 6, 7, 8, 9 }, new int[] { 3, 5, 6, 9 }, new int[] { 2, 3, 4, 6, 8 }, new int[] { 3, 6, 8 }, new int[] { 2, 3, 4, 5, 6, 7, 8 }, new int[] { 3, 6, 9 }, new int[] { 2, 4, 5, 6, 9 }, new int[] { 1, 5, 6 }, new int[] { 0 } }; int[][] xin = new int[10][] { new int[] {3,9 }, new int[] { 1,2,3,4,5,6,7,8 }, new int[] { 1,4,6}, new int[] {2,4,6}, new int[] {1,2,3,4,5,6,7,8,9 }, new int[] { 3,6,8 }, new int[] {2,3,4,5,6,8 }, new int[] { 1,3,4,6,8 }, new int[] {1,3,4,5,6,8}, new int[] {2,3,5} }; int[][] nian = new int[10][] { new int[] { 3}, new int[] { 3 }, new int[] { 2,4,5,6,7,8 }, new int[] {1,2,5}, new int[] {3,4,5,6,7,8 }, new int[] { 2,5 }, new int[] {2,5 }, new int[] {1,2,3,4,5,6,7,8,9}, new int[] {5}, new int[] {} }; int[][] kuai = new int[10][] { new int[] { 2,6}, new int[] { 2,6 }, new int[] { 2,5,6,7,8 }, new int[] {1,2,3,4,6,8}, new int[] { 1,2,6,8}, new int[] { 2,4,5,6,7,8,9 }, new int[] { 2,6,7}, new int[] { 2,6,7 }, new int[] {2,5,8}, new int[] {2,4,9} }; int[][] le = new int[10][] { new int[] { 8}, new int[] { 2,3,4,5,6,7}, new int[] { 2,5 }, new int[] {2,5}, new int[] { 2,3,4,5,6,7,8,9}, new int[] { 5 }, new int[] { 3,5,7}, new int[] {2,5,8}, new int[] {1,5,9}, new int[] {4,5} }; #endregion Random r = new Random(); ZYPHappy zyp = new ZYPHappy(); zyp.ImgStr = img[2].ToString(); //新年快乐 zyp.ImgStr = img[r.Next(0, 9)].ToString(); zyp.ToZ(xin, 30, 25, ConsoleColor.Blue); zyp.ImgStr = img[r.Next(0, 9)].ToString(); zyp.ToZ(nian, 50, 25, ConsoleColor.Yellow); zyp.ImgStr = img[r.Next(0, 9)].ToString(); zyp.ToZ(kuai, 70, 25, ConsoleColor.DarkRed); zyp.ToZ(kuai, 70, 25, ConsoleColor.DarkRed); zyp.ImgStr = img[r.Next(0, 9)].ToString(); zyp.ToZ(le, 90, 25, ConsoleColor.Gray); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("/t/t/tHappy new year!^___^"); Console.ForegroundColor = ConsoleColor.White; //zyp.ImgStr = img[r.Next(0, 9)].ToString(); //zyp.ToZ(_zheng, 2, 15, ConsoleColor.Blue); //zyp.ImgStr = img[r.Next(0, 9)].ToString(); //zyp.ToZ(_ye, 22, 15, ConsoleColor.Yellow); //zyp.ImgStr = img[r.Next(0, 9)].ToString(); //zyp.ImgStr = img[r.Next(0, 9)].ToString(); //zyp.ToZ(_ping, 42, 15, ConsoleColor.Gray); } private int GetN(ref int i) { i += 9; return i; } private void PrintSplit(int left, int top, int length) { tep += 9; string sp = ""; sp += GroundSplitStart; for (int i = 0; i < length; i++) { sp += GroundSplit; } sp += GroundSplitEnd; Console.CursorTop = top; Console.CursorLeft = left; Console.WriteLine(" " + sp); } private void PrintPoint(int i, int left, int top, int height, bool shine) { tep += 9; Console.CursorTop = top; if (shine) { if (i % 2 == 0) { Console.CursorLeft = left; Console.WriteLine(GroundPo); Console.CursorLeft = left; Console.CursorTop = top + height; Console.WriteLine(GroundPo); } } else { Console.CursorLeft = left; Console.WriteLine(GroundPo); Console.CursorLeft = left; Console.CursorTop = top + height; Console.WriteLine(GroundPo); } } private void PrintNumber(int i, int left, int top) { switch (i) { case 0: Zero(); break; case 1: One(); break; case 2: Two(); break; case 3: Three(); break; case 4: Four(); break; case 5: Five(); break; case 6: Six(); break; case 7: Seven(); break; case 8: Eight(); break; case 9: Nine(); break; } tep += 9; PrintArray(left, top); } private void PrintArray(int left, int top) { Console.CursorTop = top; for (int i = 0; i < str.GetLength(0); i++) { Console.CursorLeft = left; Console.Write(" "); for (int j = 0; j < str.GetLength(1); j++) { Console.Write(str[i, j]); } Console.WriteLine(); } } public string[,] Zero() { for (int i = 0; i < str.GetLength(0); i++) { for (int j = 0; j < str.GetLength(1); j++) { str[i, j] = " "; if (i == 0 || (i == str.GetLength(0) - 1) || j == 0 || (j == str.GetLength(1) - 1)) str[i, j] = GroundImg; if ((i == 0) && (j == 0)) str[i, j] = LeftTop; if ((i == 0) && (j == str.GetLength(1) - 1)) str[i, j] = RightTop; if ((i == str.GetLength(0) - 1) && (j == 0)) str[i, j] = LeftBottom; if ((i == str.GetLength(0) - 1) && (j == str.GetLength(1) - 1)) str[i, j] = RightBottom; } } return str; } public string[,] One() { for (int i = 0; i < str.GetLength(0); i++) { for (int j = 0; j < str.GetLength(1); j++) { str[i, j] = " "; if (j == str.GetLength(1) - 1) str[i, j] = GroundImg; if ((i == 0) && (j == str.GetLength(1) - 1)) str[i, j] = LeftTop; if ((i == str.GetLength(0) - 1) && (j == str.GetLength(1) - 1)) str[i, j] = LeftBottom; } } return str; } public string[,] Two() { for (int i = 0; i < str.GetLength(0); i++) { for (int j = 0; j < str.GetLength(1); j++) { str[i, j] = " "; if (i == 0 || (i == str.GetLength(0) - 1) || i == str.GetLength(0) / 2 || ((j == 0) && (i > str.GetLength(0) / 2)) || ((j == str.GetLength(1) - 1) && (i < str.GetLength(0) / 2))) str[i, j] = GroundImg; if ((i == 0) && (j == 0)) str[i, j] = LeftTop; if ((i == 0) && (j == str.GetLength(1) - 1)) str[i, j] = RightTop; if ((i == str.GetLength(0) - 1) && (j == 0)) str[i, j] = LeftBottom; if ((i == str.GetLength(0) - 1) && (j == str.GetLength(1) - 1)) str[i, j] = RightBottom; } } return str; } public string[,] Three() { for (int i = 0; i < str.GetLength(0); i++) { for (int j = 0; j < str.GetLength(1); j++) { str[i, j] = " "; if (i == 0 || (i == str.GetLength(0) - 1) || i == str.GetLength(0) / 2 || ((j == str.GetLength(1) - 1))) str[i, j] = GroundImg; if ((i == 0) && (j == 0)) str[i, j] = LeftTop; if ((i == 0) && (j == str.GetLength(1) - 1)) str[i, j] = RightTop; if ((i == str.GetLength(0) - 1) && (j == 0)) str[i, j] = LeftBottom; if ((i == str.GetLength(0) - 1) && (j == str.GetLength(1) - 1)) str[i, j] = RightBottom; } } return str; } public string[,] Four() { for (int i = 0; i < str.GetLength(0); i++) { for (int j = 0; j < str.GetLength(1); j++) { str[i, j] = " "; if (((j == str.GetLength(1) - 1)) || (j == 0 && i < str.GetLength(0) / 2) || i == str.GetLength(0) / 2) str[i, j] = GroundImg; if ((i == 0) && (j == 0)) str[i, j] = LeftTop; if ((i == 0) && (j == str.GetLength(1) - 1)) str[i, j] = RightTop; if ((i == str.GetLength(0) - 1) && (j == str.GetLength(1) - 1)) str[i, j] = RightBottom; } } return str; } public string[,] Five() { for (int i = 0; i < str.GetLength(0); i++) { for (int j = 0; j < str.GetLength(1); j++) { str[i, j] = " "; if (i == 0 || (i == str.GetLength(0) - 1) || i == str.GetLength(0) / 2 || ((j == str.GetLength(1) - 1) && i > str.GetLength(0) / 2) || ((j == 0) && i < str.GetLength(0) / 2)) str[i, j] = GroundImg; if ((i == 0) && (j == 0)) str[i, j] = LeftTop; if ((i == 0) && (j == str.GetLength(1) - 1)) str[i, j] = RightTop; if ((i == str.GetLength(0) - 1) && (j == 0)) str[i, j] = LeftBottom; if ((i == str.GetLength(0) - 1) && (j == str.GetLength(1) - 1)) str[i, j] = RightBottom; } } return str; } public string[,] Six() { for (int i = 0; i < str.GetLength(0); i++) { for (int j = 0; j < str.GetLength(1); j++) { str[i, j] = " "; if (i == 0 || (i == str.GetLength(0) - 1) || i == str.GetLength(0) / 2 || ((j == str.GetLength(1) - 1) && i > str.GetLength(0) / 2) || j == 0) str[i, j] = GroundImg; if ((i == 0) && (j == 0)) str[i, j] = LeftTop; if ((i == 0) && (j == str.GetLength(1) - 1)) str[i, j] = RightTop; if ((i == str.GetLength(0) - 1) && (j == 0)) str[i, j] = LeftBottom; if ((i == str.GetLength(0) - 1) && (j == str.GetLength(1) - 1)) str[i, j] = RightBottom; } } return str; } public string[,] Seven() { for (int i = 0; i < str.GetLength(0); i++) { for (int j = 0; j < str.GetLength(1); j++) { str[i, j] = " "; if (i == 0 || j == str.GetLength(1) - 1) str[i, j] = GroundImg; if ((i == 0) && (j == 0)) str[i, j] = LeftTop; if ((i == 0) && (j == str.GetLength(1) - 1)) str[i, j] = RightTop; if ((i == str.GetLength(0) - 1) && (j == str.GetLength(1) - 1)) str[i, j] = RightBottom; } } return str; } public string[,] Eight() { for (int i = 0; i < str.GetLength(0); i++) { for (int j = 0; j < str.GetLength(1); j++) { str[i, j] = " "; if (i == 0 || (i == str.GetLength(0) - 1) || i == str.GetLength(0) / 2 || j == str.GetLength(1) - 1 || j == 0) str[i, j] = GroundImg; if ((i == 0) && (j == 0)) str[i, j] = LeftTop; if ((i == 0) && (j == str.GetLength(1) - 1)) str[i, j] = RightTop; if ((i == str.GetLength(0) - 1) && (j == 0)) str[i, j] = LeftBottom; if ((i == str.GetLength(0) - 1) && (j == str.GetLength(1) - 1)) str[i, j] = RightBottom; } } return str; } public string[,] Nine() { for (int i = 0; i < str.GetLength(0); i++) { for (int j = 0; j < str.GetLength(1); j++) { str[i, j] = " "; if (i == 0 || (i == str.GetLength(0) - 1) || i == str.GetLength(0) / 2 || j == str.GetLength(1) - 1 || (j == 0 && i < str.GetLength(0) / 2)) str[i, j] = GroundImg; if ((i == 0) && (j == 0)) str[i, j] = LeftTop; if ((i == 0) && (j == str.GetLength(1) - 1)) str[i, j] = RightTop; if ((i == str.GetLength(0) - 1) && (j == 0)) str[i, j] = LeftBottom; if ((i == str.GetLength(0) - 1) && (j == str.GetLength(1) - 1)) str[i, j] = RightBottom; } } return str; } } class ZYPHappy { private string img = "¤●■〓◆◇◎☆※★"; public int left = 0; public int top = 0; public ZYPHappy() { Console.SetBufferSize(300, 400); Console.SetWindowSize(120, 40); } public string ImgStr = "■"; public void ToZ(int[][] zypP, int left, int top, ConsoleColor color) { string[,] zheng = new string[10, 10]; AntoValue(zheng); for (int i = 0; i < zypP.GetLength(0); i++) { for (int j = 0; j < zypP[i].GetLength(0); j++) { zheng[i, zypP[i][j]] = ImgStr; } } Console.ForegroundColor = color; Console.CursorLeft = left; Console.CursorTop = top; Console.WriteLine(); for (int i = 0; i < zheng.GetLength(0); i++) { Console.CursorLeft = left; for (int j = 0; j < zheng.GetLength(1); j++) { Console.Write(zheng[i, j]); } Console.WriteLine(); } Console.ForegroundColor = ConsoleColor.White; } public void AntoValue(string[,] ping) { for (int i = 0; i < ping.GetLength(0); i++) { for (int j = 0; j < ping.GetLength(1); j++) { ping[i, j] = " "; } } } } }