This tutorial series is for the entry-level game programmer who wants to start with something easy.
You will see that the code is not the most efficient, but it's easy to understand.
So let's start!
Part 1: setting up the console windowIn this part we will create the console window, change it's size etc. to make it ready for our game output.
But at first the basics of the C# console:
Console.Write("text"); //writes "text"
Console.WriteLine("text"); //writes "text" and adds the newline command ("\n") at the end
Console.ReadKey(); //waits for the user to press a key
Console.ReadLine(); //waits for user input and the [Enter] key
These commands are the most important ones.
Now let's create the console application. I am using Visual Studio 2015 with version 4.6.1 of the .NET Framework.
To create a new project follow these steps:
File ---> New ---> Project ---> Console Application
Or: Ctrl + Shift + N ---> Console Application
Now enter the name of your project and press Enter
After it has loaded you should see a bit of code. Change it to
using System;
namespace Tutorial //change "Tutorial" to your namespace
{
public static class Program
{
static void Main()
{
}
}
}
Now we will write the method that changes the console window to our preferences.
using System;
namespace Tutorial //change "Tutorial" to your namespace
{
public static class Program
{
static bool IsInitialized = false;
public static long ViewportWidth, ViewportHeight;
static void Main()
{
if (IsInitialized.Equals(false))
Initialize();
Console.ReadKey();
}
static void Initialize()
{
Console.Title = "Fun Game";
Console.SetWindowSize(140, 40);
Console.SetBufferSize(140, 40);
ViewportWidth = Console.WindowWidth;
ViewportHeight = Console.WindowHeight;
IsInitialized = true;
}
}
}
If you now press F5, you should see the console window with the size and title you set.
This was part 1; in the next part we will create useful custom console commands.