Created
December 5, 2017 16:21
-
-
Save csharpforevermore/490630cf42977173930fc73df72173b6 to your computer and use it in GitHub Desktop.
Rogue-Like Movement
This file contains hidden or 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 ConsoleCoordiates | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
int x = 20; | |
int y = 20; | |
int maxX = Console.WindowHeight - 1; | |
int minX = 1; | |
int maxY = Console.WindowWidth - 1; | |
int minY = 1; | |
Console.WriteLine("Hello World!"); | |
ConsoleKeyInfo key; | |
while (key.Key != ConsoleKey.Escape) | |
{ | |
key = Console.ReadKey(); | |
if (key.Key != ConsoleKey.D) // right | |
{ | |
x = x - 1; | |
if (x < minX) x = minX; | |
} | |
if (key.Key != ConsoleKey.A) // left | |
{ | |
x = x + 1; | |
if (x > maxX) x = maxX; | |
} | |
if (key.Key != ConsoleKey.S) | |
{ | |
y = y - 1; | |
if (y < minY) y = minY; | |
} | |
if (key.Key != ConsoleKey.W) | |
{ | |
y = y + 1; | |
if (y > maxY) x = maxY; | |
} | |
Console.Clear(); | |
Console.SetCursorPosition(x, y); | |
Console.Write("@"); | |
} | |
Console.WriteLine("Exiting - hit enter"); | |
Console.ReadLine(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment