Java 数组在我的循环之外被忽略

Java 数组在我的循环之外被忽略,java,arrays,Java,Arrays,目前我有一个非常有问题的代码,这给我带来了很大的压力。基本上,我正在尝试编写一个棋盘游戏,以圆形的形式向玩家提问,从玩家1切换到玩家2,并将他们的分数/棋盘位置保持在一个数组中。我似乎不知道如何做到这一点,但手头有一个更紧迫的问题 目前,我很困惑,为什么我用另一种方法创建的数组被完全忽略,而不是控制一系列问题的循环。我很确定我已经将数组方法正确地传递给了问题方法,因为我在循环中输入了一行代码,在每个问题之后打印出数组,它将返回一个板位置(虽然这里有一个问题,但它不是累积更新的。也就是说,在第一个

目前我有一个非常有问题的代码,这给我带来了很大的压力。基本上,我正在尝试编写一个棋盘游戏,以圆形的形式向玩家提问,从玩家1切换到玩家2,并将他们的分数/棋盘位置保持在一个数组中。我似乎不知道如何做到这一点,但手头有一个更紧迫的问题

目前,我很困惑,为什么我用另一种方法创建的数组被完全忽略,而不是控制一系列问题的循环。我很确定我已经将数组方法正确地传递给了
问题
方法,因为我在循环中输入了一行代码,在每个问题之后打印出数组,它将返回一个板位置(虽然这里有一个问题,但它不是累积更新的。也就是说,在第一个问题之后,我会在第三个问题上,但在第二个问题之后,它会告诉我向前移动5个位置到第5个位置,而不是第8个位置).当我告诉代码在循环外打印时,它只打印出0,这正是我不希望它做的

public static void main (String[] param)
{ 
   numberPlayers();
   yourQuiz();
   int[] scoretrack = scorearray();
   int diceroll = dicethrow(6);
   questions(diceroll, scoretrack);
   System.exit(0);
}  


public static int[] scorearray()
{
   int scoreplayer1 = 0;
   int scoreplayer2 = 0;
   int[] scoretrack = {scoreplayer1, scoreplayer2};
   return  scoretrack;
}

/********************************************************************************************************
This method is where the questions are asked to the players. A dice is rolled to determine what question
is asked to the player and then, depending on if the answer is correct, another dice is rolled to see how
many squares the player advances. The square that the player is on is stored in score[0] for player 1 and score[1]
for player 2. This is where the main problem lies; score[0] doesn't store the board place cumulatively, 
i.e when the second question is asked the boardplace from the first question isn't stored
*********************************************************************************************************/

public static int questions(int diceroll, int[] score)
{
String playertwo;
int ans1 = 0;
String textinput;
int result;
String continueornot = input("Do you wish to continue?");
scorearray();

 while (!continueornot.equalsIgnoreCase("No"))
 {

  if (diceroll == 1)
  { 

   while (ans1 != 19)
   {
      textinput = input("What's 9+10?");
      ans1 = Integer.parseInt(textinput);
      output("That's certainly an interesting answer"); 

    if (ans1 == 19)
    {
       output("FANTASTIC ANSWER, THAT'S CORRECT!");
       diceroll = dicethrow(diceroll);
       score[0] = score[0] + diceroll;
       output("Move forward " + diceroll + " squares. You are on square " + score[0]);
       System.out.println(score[0]); // this prints out the score here, but not cumulatively
       return yourQuiz();
    } // if they get the answer right

    else 
    {
       playertwo = input("Sorry, the answer was 19. Next player type yes to continue or no to exit");

        if (playertwo.equalsIgnoreCase("yes"))
        {
            //return questions(diceroll, score);
        }

        else 
        {
           System.out.println(score[0]);
           System.exit(0);
        }
    } // if they get the answer wrong

   } // END while 1

  } // END if dice rolls 1

} // end while answer isn't no

   System.out.println(score[0]); // this doesn't actually print out what the boardplace is, it just prints 0 twice. Array is being ignored?

   return 500; // had to return a random number because it was giving me a 'return value missing' error

如果我问的问题或代码中写的内容有任何不清楚的地方,请询问我,我会尝试澄清。我真的非常渴望得到帮助,如果有人能指出我所犯的错误,我将万分感激,因为我已经考虑了很长时间。谢谢!

您可以添加一些打印内容一步一步地观察数据,检查算法并定位问题你在哪里调用
问题
以及你传递给它的是什么数组?@Eran我没有。至少我不认为我是。我正试图做相反的事情;将数组方法传递给
问题
@超频你的
问题
方法有一个数组参数(
分数
)。你在哪里调用那个方法?你在传递什么来代替那个数组参数?@Eran我刚看了一下,我想我不会在任何地方调用那个方法。我不确定我是否误解了你,但我对这个编程东西还是比较陌生的,所以如果我听起来很傻,我很抱歉。你能详细解释一下吗?你可以解释一下逐步添加一些println以观察数据,检查算法并定位问题你在哪里调用
问题
以及你传递给它的是什么数组?@Eran我没有。至少我不认为我是。我正试图做相反的事情;将数组方法传递给
问题
@超频你的
问题
方法有一个数组参数(
分数
)。你在哪里调用那个方法?你在传递什么来代替那个数组参数?@Eran我刚看了一下,我想我不会在任何地方调用那个方法。我不确定我是否误解了你,但我对这个编程东西还比较陌生,所以如果我听起来很傻,我很抱歉。你能详细解释一下吗?