Hey guys,
So some time ago I wanted to try this myself, and got stuck quite fast and today I actually did create what I wanted back then meaning that I have definitely improved in programming. And I saw that it would be a fun little challenge for those willing to try.
What you have to do for this challenge is create a console application, and write code that will draw, something like a smiley face or anything you want, using *.
However this challenge of course bring somethings with it, I want it to pretend like it’s actually being drawn so it doesn’t immediately pop-up on screen. Furthermore you are not allowed to just write every single character, it still needs to be somewhat efficient 😉
I’m looking forward to seeing your solutions, mine is posted below, although I do recommend only watching it when you’ve finished, gotta keep it fun am I right? 😀
Click to Expand |
Show> |
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace Test
{
class Program
{
static void Main(string[] args)
{
char[] characters = "Drawing initiated...".ToCharArray();
for(int i = 0; i < characters.Length; i++)
{
Console.Write(characters[i]);
Thread.Sleep(150);
}
Console.Write("\n");
Console.WriteLine(" ");
Console.WriteLine(" ");
Draw(0);
}
static void Draw(int state)
{
switch (state)
{
case 0:
DrawEyes(6);
break;
case 1:
DrawMouth();
break;
}
}
static void DrawEyes(int width)
{
for (int i = 0; i < 4; i++)
{
Console.Write("Â Â Â Â Â Â Â Â ");
for (int j = 0; j < width; j++)
{
Console.Write("*");
Thread.Sleep(150);
}
for(int j = 0; j < 18; j++)
{
Console.Write(" ");
Thread.Sleep(50);
}
for (int j = 0; j < width; j++)
{
Console.Write("*");
Thread.Sleep(150);
}
Console.Write("\n");
}
Draw(1);
}
static void DrawMouth()
{
Console.WriteLine(" ");
Console.WriteLine(" ");
Console.Write("Â Â Â Â Â Â Â Â ");
for(int i = 0; i < 2; i++)
{
Console.Write("*");
Thread.Sleep(150);
}
for(int i = 0; i < 26; i++)
{
Console.Write(" ");
Thread.Sleep(50);
}
for(int i = 0; i < 2; i++)
{
Console.Write("*");
Thread.Sleep(150);
}
Console.Write("\n");
for (int i = 0; i < 2; i++)
{
Console.Write("Â Â Â Â Â Â Â Â Â Â ");
for(int j = 0; j < 3; j++)
{
Console.Write("*");
Thread.Sleep(150);
}
for(int j = 0; j < 20; j++)
{
Console.Write(" ");
Thread.Sleep(50);
}
for(int j = 0; j < 3; j++)
{
Console.Write("*");
Thread.Sleep(150);
}
Console.Write("Â \n");
}
for (int i = 0; i < 3; i++)
{
Console.Write("Â Â Â Â Â Â Â Â Â Â Â Â Â ");
for (int j = 0; j < 20; j++)
{
Console.Write("*");
Thread.Sleep(150);
}
Console.Write("Â Â Â Â \n");
}
Done();
}
static void Done()
{
Console.ReadLine();
}
}
}
|