Skip to content

Instantly share code, notes, and snippets.

@rdeioris
Last active October 26, 2017 16:41
Show Gist options
  • Save rdeioris/37b22e74859796f1986f4513ccfbc9dd to your computer and use it in GitHub Desktop.
Save rdeioris/37b22e74859796f1986f4513ccfbc9dd to your computer and use it in GitHub Desktop.
static void DrawChessboard(int width, int height)
{
// iterate each y
for (int y = 0; y < height; y++)
{
// iterate each x
for (int x = 0; x < width; x++)
{
// on pair y, draw black odd x
if (y % 2 == 0)
{
if (x % 2 == 0)
{
// set white
Console.BackgroundColor = ConsoleColor.White;
}
else
{
// set black
Console.BackgroundColor = ConsoleColor.Black;
}
}
else
{
if (x % 2 == 0)
{
// set black
Console.BackgroundColor = ConsoleColor.Black;
}
else
{
// set white
Console.BackgroundColor = ConsoleColor.White;
}
}
// draw the cell
Console.Write(" ");
}
// end of a line, go below
Console.WriteLine();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment