Just a funny game in console. I figured and solved this exercise to better understand threads. You need to escape from labyrinth that opens and closes its doors arbitrary. Choose difficulty(dimensions of labyrinth, lifetime, and opening doors duration) from 1 to 3 and enjoy it :)
Level 1
Level 2
Level 3
The advantage of threading is the ability to create applications that use more than one thread of execution. For example, a process can have a user interface thread that manages interactions with the user and worker threads that perform other tasks while the user interface thread waits for user input. This game - example demonstrates how to create and start a thread, and shows the interaction between two threads running simultaneously within the same process. Note that you don't have to stop or free the thread. This is done automatically by the .NET Framework common language runtime.
static void Main(string[] args)
{
Console.CursorVisible = false;
Console.OutputEncoding = System.Text.Encoding.UTF8;
do
{
Console.Clear();
Console.WriteLine("Select Level 1, 2, or 3");
string level = Console.ReadLine();
Game lab;
switch (level)
{
case "1":
lab = new Game(LabirinthSize.Small);
break;
case "2":
lab = new Game(LabirinthSize.Medium);
break;
case "3":
lab = new Game(LabirinthSize.Large);
break;
default:
lab = new Game(LabirinthSize.Medium);
break;
}
Console.Clear();
lab.DrawLife();
ThreadStart Player = new ThreadStart(lab.DrawPlayer);
Thread thread = new Thread(Player);
thread.Start();
lab.DrawLabirinth();
do
{
Console.SetCursorPosition(22, 5);
Console.WriteLine("Press Enter for Menu");
}
while (Console.ReadKey().Key != ConsoleKey.Enter);
Console.Clear();
Console.WriteLine("Press ENTER for NEW GAME, or ESC to extit game");
} while (Console.ReadKey().Key == ConsoleKey.Enter);
}
This game is written on C# 6.0, .NET Framework 4.6 Visual Studio 2015 Comunity Edition