Comfy Kat
i cant figure out whats wrong with my code
using System;
namespace The_Maze_Game
{
class Program
{
static void Main(string[] args)
{
// set appearance
Console.Title = "Maze Game";
Console.ForegroundColor = ConsoleColor.Green;
// Correct initialization of a 2D character array
while (true)
{
char[,] map =
{
{'#','#','#','#','#','#','#','#','#'},
{'#','0','0','0','0','0','0','0','#'},
{'#','#','#','0','0','0','0','0','#'},
{'#','#','@','0','0','0','0','#','#'},
{'#','0','0','0','0','0','0','#','#'},
{'#','#','#','#','#','#','#','#','#'}
};
int playerRow = 3;
int playerCol = 2;
for (int i = 0; i < map.GetLength(0); i++){
for (int j = 0; j < map.GetLength(1); j++){
Console.Write(map[i, j]);}
Console.WriteLine();}
ConsoleKeyInfo keyInfo = Console.ReadKey(intercept: true);
map[playerCol, playerRow] = '0';
if (keyInfo.Key == ConsoleKey.W){
playerCol++;}
if (keyInfo.Key == ConsoleKey.A){
playerRow--;}
if (keyInfo.Key == ConsoleKey.S){
playerCol--;}
if (keyInfo.Key == ConsoleKey.D){
playerRow++;}
map[playerCol, playerRow] = '@';
// waits before closing program
Console.ReadKey();}
}
}
}
8 replies