黑马程序员技术交流社区

标题: 一个老鼠走迷宫程序的报错问题 [打印本页]

作者: 土豆泥    时间: 2013-12-19 12:55
标题: 一个老鼠走迷宫程序的报错问题
程序体如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication4
{
    public class Maze
    {
        public bool [ , ] maze;
        public int [ , ] mark;
        Stack<int> path;
   

        public Maze(int m, int n, int per)
        {
            while (m * n < per)
            {
                Console.WriteLine("可以通行的格子太多");
                per = per / 2;
            }
            maze = new bool[m, n];
            mark = new int[m, n];
            Random rm = new Random();
            int i, j;
            for(int k=0;k<per;k++)
            {
                do{i=rm.Next()%m;
                    j=rm.Next()%n;
                }
                while(maze[i,j]);
                maze[i,j]=true;
            }
            maze[0,0]=true;
            maze[m-1,n-1]=true;
        }

        public void PrintMaze()
        {
            for (int i = 0; i < maze.GetLength(0); i++)
            {
                for (int j = 0; j < maze.GetLength(1); j++)
                {
                    if (maze(i, j))
                    {
                        Console.WriteLine("_" + " ");
                    }
                    else
                    {
                        Console.WriteLine("x " + " ");
                    }
                }
            }
            Console.WriteLine();
        }

            }
        

    class Program
    {
        static void Main(string[] args)
        {
            Maze mz = new Maze(16, 16, 180);
            mz.PrintMaze();
        }
    }
}
错误        1        “ConsoleApplication4.Maze.maze”是“字段”,但此处被当做“方法”来使用       





欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2