Created
February 20, 2014 13:38
-
-
Save squareiguana/9113733 to your computer and use it in GitHub Desktop.
Example Using Variables and the Console Object - Using Coding 101 - Episode 01
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace SquareIguana.Coding101.Example.E01 | |
{ | |
class Program | |
{ | |
/* Example on what was learned on Coding 101 - Episode 01 - Using Variables and the Console Object | |
* I made the example trying not to use "advanced" concepts, and only what the episode was trying to teach. | |
* | |
* The most useful thing in the example, I think is the use of the Console object, because in the episode and | |
* the Code Example, was only using the 4 of its methods (Write, WriteLine, Read, ReadLine), and that is good but | |
* there is more cool things that can be done with the Console, so I'm trying to use more methods for Console to | |
* demostrate some of the cool things that can be done with just that and simple variables. | |
* | |
* The Console Methods, and examples of usage can be found here: http://msdn.microsoft.com/en-us/library/System.Console_methods(v=vs.110).aspx | |
* | |
* I'm going out of my way to use only the simple concepts, this definitely needs a refactor once they go into | |
* more "advanced" topics like methods, functions, classes, constants, arrays, ifs, loops, etc. maybe I'll do | |
* a refactor or several, after some of those topics to show a more cleaner code. | |
* | |
* Definition of Refactor: To rewrite existing source code in order to improve its readability, reusability or | |
* structure without affecting its meaning or behaviour. | |
*/ | |
static void Main(string[] args) | |
{ | |
int width = 80; | |
int height = 25; | |
int border = 1; | |
ConsoleColor white = ConsoleColor.White; | |
ConsoleColor black = ConsoleColor.Black; | |
ConsoleColor cyan = ConsoleColor.DarkCyan; | |
ConsoleColor red = ConsoleColor.DarkRed; | |
ConsoleColor blue = ConsoleColor.DarkBlue; | |
ConsoleColor green = ConsoleColor.DarkGreen; | |
Console.Title = "Coding 101 - C# E01 - Using Console and Variables"; | |
Console.SetWindowSize(width, height); | |
Console.SetBufferSize(width, height); | |
Console.BackgroundColor = cyan; | |
Console.ForegroundColor = white; | |
Console.Clear(); | |
Console.BackgroundColor = white; | |
Console.MoveBufferArea(border, border, width - (border * 2), height - border, border, height - border); | |
string headerTop = " ╔══════════════════════════════════════════════════════════╗ "; | |
string headerFill = " ║ ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ ║ "; | |
string headerBottom = " ╚══════════════════════════════════════════════════════════╝ "; | |
int headerWidth = headerTop.Length; | |
int headerHeight = 5; | |
int padding = ((width - (headerWidth + (border * 2))) / 2) + border; | |
Console.BackgroundColor = cyan; | |
Console.ForegroundColor = white; | |
Console.SetCursorPosition(padding, border); | |
Console.Write(headerTop); | |
Console.SetCursorPosition(padding, border + 1); | |
Console.Write(headerFill); | |
Console.SetCursorPosition(padding, border + 2); | |
Console.Write(headerFill); | |
Console.SetCursorPosition(padding, border + 3); | |
Console.Write(headerFill); | |
Console.SetCursorPosition(padding, border + 4); | |
Console.Write(headerBottom); | |
string headerText = " CODING 101 - Example Using E01 "; // Empty spaces before and after text to make it look better | |
Console.SetCursorPosition(padding + (headerWidth / 2) - (headerText.Length / 2), border + 2); | |
Console.Write(headerText); | |
Console.BackgroundColor = white; | |
Console.ForegroundColor = black; | |
Console.SetCursorPosition(padding, border + headerHeight + 1); | |
Console.Write("Please Authenticate Yourself: "); | |
Console.ForegroundColor = blue; | |
string auth = Console.ReadLine(); | |
Console.ForegroundColor = black; | |
Console.SetCursorPosition(padding, border + headerHeight + 2); | |
Console.Write("Validating Credentials for USER: "); | |
Console.ForegroundColor = blue; | |
Console.WriteLine(auth); | |
Console.CursorVisible = false; | |
Console.ForegroundColor = red; | |
Console.SetCursorPosition(padding, border + headerHeight + 3); | |
Console.Beep(); | |
Console.Beep(); | |
Console.Beep(); | |
Console.Beep(); | |
Console.Write("Please Wait"); | |
Console.Beep(233, 800); | |
Console.Write("."); | |
Console.Beep(247, 800); | |
Console.Write("."); | |
Console.Beep(277, 800); | |
Console.Write("."); | |
Console.Beep(311, 800); | |
Console.Write("."); | |
Console.Beep(330, 800); | |
Console.Write("."); | |
Console.Beep(370, 800); | |
Console.Write("."); | |
Console.Beep(415, 800); | |
Console.ForegroundColor = green; | |
Console.SetCursorPosition(padding, border + headerHeight + 4); | |
Console.Write("Authorization of USER="); | |
Console.ForegroundColor = blue; | |
Console.Write(auth); | |
Console.ForegroundColor = green; | |
Console.WriteLine(" is VALID"); | |
Console.Beep(37, 3000); // Since this is an example for the Console object, this seem more appropiate and that is the only reason that I can think to use this instead of the code below ↓ to wait 3 seconds | |
//System.Threading.Thread.Sleep(3000); // Could have used this instead of the code above ↑ | |
Console.BackgroundColor = red; | |
Console.ForegroundColor = white; | |
Console.SetCursorPosition(padding + 2, border + 2); | |
string over = " EXAMPLE IS NOW OVER "; | |
Console.MoveBufferArea(padding + 3, border + 1, headerWidth - (3 * 2), 1, padding + 3, border + 2, '▒', white, cyan); | |
Console.SetCursorPosition((headerWidth / 2) - (over.Length / 2) + padding, border + 2); | |
Console.Write(over); | |
// The commented code below ↓ will "erase" the 4 lines that was written below the header | |
// This would be useful if I didn't write Coding 101 in ASCII, but because I am, then that code will "erase" it. | |
//Console.BackgroundColor = white; | |
//Console.ForegroundColor = white; | |
//Console.MoveBufferArea(border, border + 10, width - (border * 2), 4, border, border + headerHeight + 1); | |
Console.BackgroundColor = white; | |
Console.ForegroundColor = green; | |
padding = ((width - (68 + (border * 2))) / 2) + border; | |
Console.SetCursorPosition(padding, border + headerHeight + 1); | |
Console.Write(" ██████╗ ██████╗ ██████╗ ██╗███╗ ██╗ ██████╗ ██╗ ██████╗ ██╗"); | |
Console.SetCursorPosition(padding, border + headerHeight + 2); | |
Console.Write("██╔════╝██╔═══██╗██╔══██╗██║████╗ ██║██╔════╝ ███║██╔═████╗███║"); | |
Console.SetCursorPosition(padding, border + headerHeight + 3); | |
Console.Write("██║ ██║ ██║██║ ██║██║██╔██╗ ██║██║ ███╗ ╚██║██║██╔██║╚██║"); | |
Console.SetCursorPosition(padding, border + headerHeight + 4); | |
Console.Write("██║ ██║ ██║██║ ██║██║██║╚██╗██║██║ ██║ ██║████╔╝██║ ██║"); | |
Console.SetCursorPosition(padding, border + headerHeight + 5); | |
Console.Write("╚██████╗╚██████╔╝██████╔╝██║██║ ╚████║╚██████╔╝ ██║╚██████╔╝ ██║"); | |
Console.SetCursorPosition(padding, border + headerHeight + 6); | |
Console.Write(" ╚═════╝ ╚═════╝ ╚═════╝ ╚═╝╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═════╝ ╚═╝"); | |
Console.ForegroundColor = black; | |
padding = ((width - (65 + (border * 2))) / 2) + border; | |
Console.SetCursorPosition(padding, border + headerHeight + 8); | |
Console.Write("╦ ╦┬┌┬┐┬ ┬ ╔═╗┬─┐ ╦═╗┌─┐┌┐ ┌─┐┬─┐┌┬┐ ╔╗ ┌─┐┬ ┬ ┌─┐┌─┐┌─┐┬─┐"); | |
Console.SetCursorPosition(padding, border + headerHeight + 9); | |
Console.Write("║║║│ │ ├─┤ ╠╣ ├┬┘ ╠╦╝│ │├┴┐├┤ ├┬┘ │ ╠╩╗├─┤│ │ ├┤ │ ├┤ ├┬┘"); | |
Console.SetCursorPosition(padding, border + headerHeight + 10); | |
Console.Write("╚╩╝┴ ┴ ┴ ┴ ╚ ┴└─o ╩╚═└─┘└─┘└─┘┴└─ ┴ ╚═╝┴ ┴┴─┘┴─┘└─┘└─┘└─┘┴└─"); | |
padding = ((width - (49 + (border * 2))) / 2) + border; | |
Console.SetCursorPosition(padding, border + headerHeight + 11); | |
Console.Write("┌─┐┌┐┌┌┬┐ ╔═╗┬ ┬┌─┐┌┐┌┌┐┌┌─┐┌┐┌ ╔╦╗┌─┐┬─┐┌─┐┌─┐"); | |
Console.SetCursorPosition(padding, border + headerHeight + 12); | |
Console.Write("├─┤│││ ││ ╚═╗├─┤├─┤│││││││ ││││ ║║║│ │├┬┘└─┐├┤ "); | |
Console.SetCursorPosition(padding, border + headerHeight + 13); | |
Console.Write("┴ ┴┘└┘─┴┘ ╚═╝┴ ┴┴ ┴┘└┘┘└┘└─┘┘└┘ ╩ ╩└─┘┴└─└─┘└─┘"); | |
Console.BackgroundColor = black; | |
Console.ForegroundColor = green; | |
padding = ((width - (61 + (border * 2))) / 2) + border; | |
Console.SetCursorPosition(padding, border + headerHeight + 15); | |
Console.Write(" /') _/_ ( /_ _ _ ' _ -- / /|/| _ _ _ _ _ _ "); | |
Console.SetCursorPosition(padding, border + headerHeight + 16); | |
Console.Write(" (__()(/(- |/|/(// / /()/ -- (__()(/ / |(// (-_) ( (/ "); | |
Console.BackgroundColor = white; | |
Console.ForegroundColor = white; | |
Console.SetCursorPosition(border, border + 19); | |
Console.Read(); //Pause, doesn't matter what is written is on a white line so it doesn't show, unless it's more than 80 characters | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment