我如何在这段代码中引用石头的重量,以便我可以在我的unlockChest方法中使用它?我基本上试图将用户从对象 new Stone()) 输入的权重相加,因此它 == 组合了用户在 Chest() 构造函数中输入的值。我知道这是错误的,但我尝试了 jar1.weight,它说它不是变量。
public class Stone
{
private String name;
private int weight;
public Stone()
{
System.out.print("Enter stone name: ");
name = Global.keyboard.nextLine();
System.out.print("Enter stone weight: ");
weight = Global.keyboard.nextInt();
Global.keyboard.nextLine();
}
}
public class Jar
{
private int position;
private Stone stone;
public Jar()
{
position = 0;
stone = null;
}
public Jar(int initPos, Stone stone)
{
position = initPos;
this.stone = stone;
}
public class Ground
{
private Jar jar1;
private Jar jar2;
private Jar jar3;
private Player player;
private Chest chest;
public Ground()
{
player = new Player();
jar1 = new Jar(1, new Stone());
jar2 = new Jar(2, new Stone());
jar3 = new Jar(3, new Stone());
chest = new Chest()
}
public boolean ChestUnlocked()
{
if (jar1.weight + jar2.weight + jar3.weight == chest.combination) //the main problem
return true;
else
return false;
}
public class Chest
{
public int combination;
private int position;
private Jar jar1;
private Jar jar2;
private Jar jar3;
public Chest()
{
System.out.print("Enter chest combination (5-10): ");
combination = Global.keyboard.nextInt();
Global.keyboard.nextLine();
position = 4;
jar1 = new Jar(4, null);
jar2 = new Jar(4, null);
jar3 = new Jar(4, null);
}
炎炎设计
芜湖不芜
杨魅力
相关分类