using System.Collections.Generic;
public static void Main()
bool keyAvailable = true;
List<string> inventory = new List<string>();
DisplayGrid(gridSize, playerX, playerY, keyX, keyY, keyAvailable);
DescribeRoom(playerX, playerY);
string input = Console.ReadLine()?.Trim().ToLower();
Console.WriteLine("Goodbye!");
ProcessInput(input, ref playerX, ref playerY, gridSize, ref keyAvailable, keyX, keyY, inventory);
private static void DisplayGrid(int gridSize, int playerX, int playerY, int keyX, int keyY, bool keyAvailable)
for (int y = 0; y < gridSize; y++)
for (int x = 0; x < gridSize; x++)
if (x == playerX && y == playerY)
else if (x == keyX && y == keyY && keyAvailable)
private static void DescribeRoom(int playerX, int playerY)
if (playerX == 0 && playerY == 0)
description = "You stand at the edge of a vast wilderness. To the east, the path beckons. To the south, you hear the rustle of leaves.";
else if (playerX == 2 && playerY == 2)
description = "A clearing opens here, bathed in golden light. In the center, you see a key glinting on the ground.";
description = "The northern wind bites as you stand at the border of the unknown. Paths stretch to the east and west.";
description = "The ground beneath your feet feels firm, and the air is rich with the smell of earth. You can travel north or explore further to the east or west.";
description = "To the east, the world seems to end in a wall of mist. Paths extend to the west and south.";
description = "You are surrounded by tall grass swaying gently. Paths lead in all directions, promising adventure and mystery.";
Console.WriteLine($"\n{description}\n{art}");
private static void DisplayInstructions()
Console.WriteLine("\nUse WASD to move:");
Console.WriteLine("W = Up, A = Left, S = Down, D = Right");
Console.WriteLine("Type 'pickup key' to pick up the key if you're on it.");
Console.WriteLine("Type 'pathtokey' to get directions to the key.");
Console.WriteLine("Press 'I' to view your inventory.");
Console.WriteLine("Press 'Q' to quit.");
private static void ProcessInput(string input, ref int playerX, ref int playerY, int gridSize, ref bool keyAvailable, int keyX, int keyY, List<string> inventory)
if (playerY > 0) playerY--;
if (playerX > 0) playerX--;
if (playerY < gridSize - 1) playerY++;
if (playerX < gridSize - 1) playerX++;
AttemptPickupKey(ref keyAvailable, playerX, playerY, keyX, keyY, inventory);
DisplayPathToKey(playerX, playerY, keyX, keyY);
DisplayInventory(inventory);
Console.WriteLine("Invalid input. Use WASD, 'pickup key', 'pathtokey', 'I', or 'Q'.");
private static void AttemptPickupKey(ref bool keyAvailable, int playerX, int playerY, int keyX, int keyY, List<string> inventory)
if (playerX == keyX && playerY == keyY && keyAvailable)
Console.WriteLine("You picked up the key!");
Console.WriteLine("There is no key here to pick up.");
private static void DisplayInventory(List<string> inventory)
Console.WriteLine("Inventory:");
foreach (string item in inventory)
Console.WriteLine("- " + item);
Console.WriteLine("Your inventory is empty.");
private static void DisplayPathToKey(int playerX, int playerY, int keyX, int keyY)
Console.WriteLine("Path to the key:");
int deltaX = keyX - playerX;
int deltaY = keyY - playerY;
Console.WriteLine($"Move right {deltaX} step(s)");
Console.WriteLine($"Move left {Math.Abs(deltaX)} step(s)");
Console.WriteLine($"Move down {deltaY} step(s)");
Console.WriteLine($"Move up {Math.Abs(deltaY)} step(s)");