目前在遊戲中,它會問某些問題,如你收集了所有的鍵,殺死所有的老闆等。 但是,當它關閉到結尾,並要求「你想用哪個鍵?「。它確實是好的,但一旦得到它的門部分,它實際上並沒有拿到鑰匙的價值,它只是輸出0創建一個基於文本的遊戲,我卡住
的代碼主片
public static int possibleKey()
{
SetnGet sng = new SetnGet();
int keys;
do
{
System.out.println("Which key would you like to use?");
keys = in.nextInt();
}
while(keys != 1 && keys != 2 && keys != 3);
return keys;
}
public static int possibleLevel()
{
SetnGet sng = new SetnGet();
System.out.println("Which door would you like to enter? - 1, 2, 3 or 4");
int level;
if(sng.accessibleKey() == 3)
{
do
{
System.out.println("You have all three keys, you have complete access");
level = in.nextInt();
}
while(level != 1 && level != 2 && level != 3);
}
else
{
do
{
System.out.println("You have no level access");
level = in.nextInt();
}
while(level != 1 && level != 2 && level != 3 && level != 4);
}
return level;
}
設定,並從獲得所述SetnGet類
private int possibleKey;
private int possibleLevel;
public int setPossibleKey()
{
return possibleKey;
}
public void setPossibleKey(int possibleKey)
{
this.possibleKey = possibleKey;
}
public int getPossibleLevel()
{
return possibleLevel;
}
public void setPossibleLevel(int possibleLevel)
{
this.possibleLevel = possibleLevel;
}
Did you逐步執行IDE調試器中的代碼?你發現了什麼? –
我發現每次運行IDE調試器時都會測試每一位數據。它從sng.accessibleKey到System.out.println(「你沒有級別訪問」); – Questionable