Copying and Pasting cs Code
In cs, like in almost any computer programming language, reading data from a file can be tricky. You add extra lines of code to tell the computer what to do. Sometimes you can copy and paste these lines from other peoples’ code.
For example, you can follow the pattern in this listing: static void StartupScreen()
{
string heading = "A simple tron-like game";
Console.CursorLeft = Console.BufferWidth / 2 - heading.Length / 2;
Console.WriteLine(heading);
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("Player 1's controls:\n");
Console.WriteLine("W - Up");
Console.WriteLine("A - Left");
Console.WriteLine("S - Down");
Console.WriteLine("D - Right");
string longestString = "Player 2's controls:";
int cursorLeft = Console.BufferWidth - longestString.Length;
Console.CursorTop = 1;
Console.ForegroundColor = ConsoleColor.Cyan;
Console.CursorLeft = cursorLeft;
Console.WriteLine("Player 2's controls:");
Console.CursorLeft = cursorLeft;
Console.WriteLine("Up Arrow - Up");
Console.CursorLeft = cursorLeft;
Console.WriteLine("Left Arrow - Left");
Console.CursorLeft = cursorLeft;
Console.WriteLine("Down Arrow - Down");
Console.CursorLeft = cursorLeft;
Console.WriteLine("Right Arrow - Right");
Console.ReadKey();
Console.Clear();
}
{
string heading = "A simple tron-like game";
Console.CursorLeft = Console.BufferWidth / 2 - heading.Length / 2;
Console.WriteLine(heading);
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("Player 1's controls:\n");
Console.WriteLine("W - Up");
Console.WriteLine("A - Left");
Console.WriteLine("S - Down");
Console.WriteLine("D - Right");
string longestString = "Player 2's controls:";
int cursorLeft = Console.BufferWidth - longestString.Length;
Console.CursorTop = 1;
Console.ForegroundColor = ConsoleColor.Cyan;
Console.CursorLeft = cursorLeft;
Console.WriteLine("Player 2's controls:");
Console.CursorLeft = cursorLeft;
Console.WriteLine("Up Arrow - Up");
Console.CursorLeft = cursorLeft;
Console.WriteLine("Left Arrow - Left");
Console.CursorLeft = cursorLeft;
Console.WriteLine("Down Arrow - Down");
Console.CursorLeft = cursorLeft;
Console.WriteLine("Right Arrow - Right");
Console.ReadKey();
Console.Clear();
}