为什么我的二维阵列不打印符号?

时间:2017-09-26 13:47:19

标签: c# arrays 2d

我试图创建一个自上而下的2D游戏,使用2d数组和不同的类来处理不同的"块"在游戏中(如墙壁,角色,门等) 为什么不打印出类中的符号?

public class Karta
{
    public void Map()
    {

        const int ROWS = 16, COLUMNS = 24;
        Blocks[,] map = new Blocks[COLUMNS, ROWS];
        int playerRow = 3, playerColumn = 11;

        // Create map
        for (int row = 0; row < ROWS; row++)
        {
            for (int column = 0; column < COLUMNS; column++)
            {

                if (row == 0 || row == ROWS - 1 || column == 0 || column == COLUMNS - 1)
                    map[column, row] = new Wall();

                else
                    map[column, row] = new EmptySpace();
            }
        }

        while (true)
        {
            // Draw the map
            string buffer = "";
            for (int row = 0; row < ROWS; row++)
            {
                string line = "";
                for (int column = 0; column < COLUMNS; column++)
                {
                    if (column == playerColumn && row == playerRow)
                        line += new Character();
                    else
                        line += map[column, row];
                }
                //Console.WriteLine(line);
                buffer += line + "\n";
            }
            Console.CursorLeft = 0;
            Console.CursorTop = 0;
            Console.Write(buffer);

            var key = Console.ReadKey();
            if (key.Key == ConsoleKey.W)
                playerRow--;
            else if (key.Key == ConsoleKey.A)
                playerColumn--;
            else if (key.Key == ConsoleKey.S)
                playerRow++;
            else if (key.Key == ConsoleKey.D)
                playerColumn++;
        }//while
    }//Map

Block基类:

public abstract class Blocks
{
    public abstract string printBlock();
}

Wall子类:

public class Wall : Blocks
{

    public override string printBlock()
    {
        return "#";
    }

}

其他课程看起来像&#34; Wall&#34;但是有不同的符号。

0 个答案:

没有答案