XmasTree
public static void XmasTree(String name) { string[,] tree = { { " "," "," "," "," "," ","*"," "," "," "," "," "," "}, { " "," "," "," "," ","*","*","*"," "," "," "," "," "}, { " "," "," "," ","*","*","*","*","*"," "," "," "," "}, { " "," "," "," "," ","*","*","*"," "," "," "," "," "}, { " "," "," ","*","*","*","*","*","*","*"," "," "," "}, { " "," ","*","*","*","*","*","*","*","*","*"," "," "}, { " "," "," "," ","*","*","*","*","*"," "," "," "," "}, { " ","*","*","*","*","*","*","*","*","*","*","*"," "}, { "*","*","*","*","*","*","*","*","*","*","*","*","*"}, { " "," "," "," "," "," ","*"," "," "," "," "," "," "}, { " "," "," "," "," "," ","*"," "," "," "," "," "," "}, }; int rows = tree.GetLength(0); int cols = tree.GetLength(1); int i = 0; int j = 0; bool red = true; int nameLen = name.Length; int k = 0; while (i < rows) { j = 0; while (j < cols) { if (tree[i,j] == "*") { Console.BackgroundColor = ConsoleColor.DarkGreen; if (red == true) { Console.ForegroundColor = ConsoleColor.Red; red = false; } else { Console.ForegroundColor = ConsoleColor.Yellow; red = true; } if (k == nameLen) k = 0; tree[i, j] = Convert.ToString(name[k]); k++; } Console.Write(tree[i,j]); Console.ResetColor(); j++; } Console.WriteLine(); i++; } }
Leave a Comment