【发布时间】:2021-07-15 13:58:29
【问题描述】:
我正在尝试制作主机游戏,但我对以下代码(以及未来代码)有疑问
Node n1 = new Node("You Are in a Snowy biome, you notice your Crashed Vehicle behind you.", map1, n9, n2, null, n3, null, null, "You Notice Your Crashed Vehicle, it is Beyond use now.", null);
Node n2 = new Node("You Notice a Metal Lamp Post Standing Tall, the Light is on.", map2, n8, n4, null, n1, "You Move Past the Lamp Post.", null, "You see Part of your Crashed Vehicle, it was Pretty Long.", "This was where you Crashed.");
Node n3 = new Node("You Notice a Box with a Red Plus Sign on it.", map3, n10, n1, null, null, "You Walk Towards the box and open the Lid...", ItemN3.GetItem());
Node n4 = new Node(null, map4, n7, n5, null, n2, null, null, "A huge Wall of Fire Blocks the whole of the South.", "You Move back To the Lamp Post.");
Node n5 = new Node("You See A massive hole to the East.", map5, n6, null, null, n4, "You See the hole, Around 54ft Deep.", null, "The Wall of Fire Continues.", null);
节点采用这些参数:
但是我有错误告诉我在声明之前我不能使用Node,但是当我将它移到错误上方时,我在更下方的其他节点之一上得到相同的错误。所以它只是一个无限循环的错误。
我不知道如何解决这个问题。如果可能,请有人帮忙吗?
【问题讨论】:
-
我的建议:停止在构造函数中做所有事情。构造后分配属性,或引入接受邻居的方法。
-
@Llama 所以你想让我做一个单独的方法来创建节点?
-
@Isparia OP 在 n1 的构造函数中引用了 n9、n2 和 n3。在 n2 中,他们引用了 n1。
-
@Llama 你是对的,如果我将对象构造为空然后我运行一个采用所有参数的方法,它将起作用。谢谢你:))