我希望这种称为“ roll”的方法在每次调用它的int称为“ spacePoints”时都会倒数。它可以工作,但是每次都从100开始。我需要它开始每次调用该方法时要删除的点。

int spacePoints = 100;

public void roll (){
    pointsRolled = ((int) (Math.random() * 10)+ 1);
    if (pointsRolled % 3 ==0){
    System.out.println("You must fight!!!");

    } else {
      spacePoints = spacePoints- pointsRolled;
     System.out.println("You have " + spacePoints + "  to go.");

   }

   }

最佳答案

正如@ John3136所提到的,您的问题有点不清楚,但是我敢打赌,您需要阅读有关static关键字的更多信息并理解class members

09-10 18:54