我正在制作这个游戏,但我遇到了结构问题。我创建了一个名为 Structure 的类,其他类如 Traps、Shelter、Fireplace 都继承自该类。游戏中的瓷砖有自己的类(瓷砖),并在该瓷砖上有一个结构列表。我可以成功地在列表中包含的图块上构建结构。当我尝试从陷阱等类中访问函数时,问题就来了。它不起作用。我只能使用基类结构中的函数。
平铺列表:
class Tile
{
public List<Structure> Structures = new List<Structure>();
}
我如何建造陷阱或其他建筑物:
bool anyFireplace = Bundle.map.tile[Bundle.player.X, Bundle.player.Y].Structures.OfType<Shelter>().Any();
if (!anyFireplace)
{
woodlogsCost = 4;
if (Bundle.player.Woodlogs - woodlogsCost >= 0)
{
Bundle.map.tile[Bundle.player.X, Bundle.player.Y].Structures.Add(new Shelter(Bundle.player.X, Bundle.player.Y));
Bundle.player.Woodlogs -= woodlogsCost;
}
}
当我绘制结构时(这是我的问题所在,请注意评论)
foreach (Structure s in Bundle.map.tile[x, y].Structures)
{
if (s is Fireplace)
{
//This is the function from base class Strucure
s.ColorBody(g, 10, x - minx, y - miny, 0, Brushes.Firebrick);
// The function that I wan´t to use but can´t be used
//s.ColorBody(g, x - minx, y - miny);
}
if (s is Shelter)
{
s.ColorBody(g, 10, x - minx, y - miny, 1, Brushes.ForestGreen);
}
if (s is Sleepingplace)
{
s.ColorBody(g, 10, x - minx, y - miny, 2, Brushes.Brown);
}
if (s is Trap)
{
s.ColorBody(g, 10, x - minx, y - miny, 3, Brushes.Silver);
}
if (s is Barricade)
{
s.ColorBody(g, 10, x - minx, y - miny, 4, Brushes.DarkOliveGreen);
}
}
Soo... 我想知道如何访问我不想使用的功能?