Έχουν δημοσιευτεί
Σάββατο, 23 Δεκεμβρίου 2006 11:06 μμ
από το μέλος
PALLADIN
Εύχομαι σε όλο το community, Καλά Χριστούγεννα και να έχουμε ένα ευτυχισμένο και δημιουργικό 2007!!!
Κλείνοντας, είπα να στολίσω το blog μου με τα ανάλογα δεντράκια μιας και οι μέρες το ζητούν.




class Program
{
static int GetIndexFromRule(char first, char second, char third)
{
if (first == ' ' && second == ' ' && third == ' ')
return 0;
else if (first == ' ' && second == ' ' && third == '*')
return 1;
else if (first == ' ' && second == '*' && third == ' ')
return 2;
else if (first == ' ' && second == '*' && third == '*')
return 3;
else if (first == '*' && second == ' ' && third == ' ')
return 4;
else if (first == '*' && second == ' ' && third == '*')
return 5;
else if (first == '*' && second == '*' && third == ' ')
return 6;
else //if (first == '*' && second == '*' && third == '*')
return 7;
}
static IEnumerable<string> ExecuteRule(string rule, int times)
{
string space = " * ";
string newSpace = string.Empty;
yield return space;
for(int counter = 2; counter <= times; counter++)
{
for(int i = 1; i < space.Length - 1; i++)
{
newSpace += rule[GetIndexFromRule(space[i - 1], space[i], space[i + 1])];
}
yield return newSpace;
space = String.Format(" {0} ", newSpace);
newSpace = string.Empty;
}
}
static void Center(int row, string text)
{
int left = ((Console.WindowWidth - 1) - text.Length) / 2;
Console.SetCursorPosition(left, row);
Console.Write(text);
}
static void PrintRule(string rule)
{
Console.Clear();
Console.ForegroundColor = ConsoleColor.Green;
int counter = 1;
foreach(string line in ExecuteRule(rule, 40))
{
Center(counter++, line);
}
Console.ReadKey();
}
static void Main(string[] args)
{
PrintRule(" **** "); // rule 30
PrintRule(" *******"); // rule 254
PrintRule(" * *****"); // rule 250
PrintRule(" * ** * "); // rule 90
}
}
Υλικά κατασκευης: A New Kind Of Science