My int dice
in MovePath()
method needs to get the value of int step
in GetRollDice()
method.
I'm using Java.
How should I do that?
public static int getRollDice(){
int[] diceStep= {-2,-1,1,2,3};
int randomStep = new Random().nextInt(diceStep.length);
int step = diceStep[randomStep];
return step;
}
public static int MovePath(Integer dice,Integer path){
// int dice = step value from GetRollDice
//Get Initial Path
//Next path = roll dice value + initial path
return path;
}
You just have to call your method, no need to redeclare dice
:
public static int MovePath(Integer dice,Integer path){
dice = getRollDice();
//Get Initial Path
//Next path = roll dice value + initial path
return path;
}
Keep in mind that everything in Java is a reference to an Object
... everything but primitive types like int
, short
, etc...
See What is the difference between Integer and int in Java? for more information about this.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.