【发布时间】:2011-11-23 22:05:58
【问题描述】:
我正在尝试为我的程序创建一些简单的类,但我被 Tile[,] 类“theGrid”对象的字段类型不一致的可访问性错误难住了。我已经查看了其他一些解决方案,并将所有内容都设置为公开,但我仍然不知道该怎么做。
你能告诉我如何解决这个问题吗?
public class Level
{
public Tile[,] theGrid;
public Tile[,] TheGrid
{
get { return theGrid; }
set { theGrid = value;}
}
public static Tile[,] BuildGrid(int sizeX, int sizeY)
{
Tile earth = new Tile("Earth", "Bare Earth. Easily traversable.", ' ', true);
//this.createTerrain();
for (int y = 0; y < sizeY; y++)
{
for (int x = 0; x < sizeX; x++)
{
theGrid[x, y] = earth;
}
}
return theGrid;
}
这是 tile 类的简化版本:
public class Tile
{
//all properties were set to public
public Tile()
{
mineable = false;
symbol = ' ';
traversable = true;
resources = new List<Resource>();
customRules = new List<Rule>();
name = "default tile";
description = "A blank tile";
area = "";
}
public Tile(string tName, string tDescription, char tSymbol, bool tTraversable)
{
resources = new List<Resource>();
customRules = new List<Rule>();
area = "";
symbol = tSymbol;
this.traversable = tTraversable;
this.name = tName;
this.description = tDescription;
mineable = false;
}
public void setArea(string area)
{
this.area = area;
}
}
如果你能在这方面给我任何帮助,我将不胜感激。
【问题讨论】:
-
你能显示你的
Tile类的属性/字段吗?