1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
public class QueFaitCetteClasse
{
public QueFaitCetteClasse()
{
Console.WindowHeight = Console.LargestWindowHeight - 10;
Console.SetWindowPosition(0, 0);
Console.Clear();
int h = 9;
int w = 15;
int WH = Console.WindowHeight - h;
int WW = Console.WindowWidth - w;
string lines = string.Empty;
for (int i = 0; i < WH; i += h)
{
for (int k = 0; k < WW; k++)
{
Console.WriteLine(lines);
DrawInvader(k);
Thread.Sleep(200);
Console.Clear();
}
AddBlankLines(h, ref lines);
Console.Clear();
}
}
#region PRIVATE MEMBERS
private static void AddBlankLines(int nb, ref string lines)
{
for (int j = 0; j < nb; j++)
{
lines += "\r\n";
}
}
private static void DrawInvader(int left)
{
string tabs = string.Empty;
for (int i = 0; i < left; i++)
{
tabs += " ";
}
Console.ForegroundColor = ConsoleColor.Green;
StringBuilder sb = new StringBuilder();
if (left % 2 == 0)
Even(sb, tabs);
else
Odd(sb, tabs);
Console.Write(sb.ToString());
Console.ResetColor();
}
private static void Even(StringBuilder sb, string tabs)
{
sb.AppendFormat("{0} # # \r\n", tabs);
sb.AppendFormat("{0} # # \r\n", tabs);
sb.AppendFormat("{0} ########### \r\n", tabs);
sb.AppendFormat("{0} ### ##### ### \r\n", tabs);
sb.AppendFormat("{0}###############\r\n", tabs);
sb.AppendFormat("{0}# ########### #\r\n", tabs);
sb.AppendFormat("{0}# # # #\r\n", tabs);
sb.AppendFormat("{0} ### ### \r\n", tabs);
}
private static void Odd(StringBuilder sb, string tabs)
{
sb.AppendFormat("{0} # # \r\n", tabs);
sb.AppendFormat("{0} # # \r\n", tabs);
sb.AppendFormat("{0}# ########### #\r\n", tabs);
sb.AppendFormat("{0}#### ##### ####\r\n", tabs);
sb.AppendFormat("{0}###############\r\n", tabs);
sb.AppendFormat("{0} ########### \r\n", tabs);
sb.AppendFormat("{0} # # \r\n", tabs);
sb.AppendFormat("{0} ## ## \r\n", tabs);
}
#endregion
} |
Partager