как поменять время делать в java? - PullRequest
0 голосов
/ 21 апреля 2020

Это мой java код, может кто-нибудь помочь мне изменить, пока l oop делать, а l oop in java, пожалуйста, спасибо :)

 while (round<=25){
        //Player takes turn
        Player currPlayer = players.get(playerIdx);
        int roll = currPlayer.getRoll();;
        //Update the board
        curr = currPlayer.getNextposition();
        System.out.printf("%s\n",currPlayer.getName());
        System.out.printf("Old: %d\n",currPlayer.getCurrposition());
        System.out.printf("Dice: %d\n",currPlayer.getRoll());
        System.out.printf("New: %d\n",currPlayer.getNextposition());
        if(curr==100) {
            menu=-1;
            break;
        }

Код похож на это? Я пытаюсь:

do{
    Player currPlayer = players.get(playerIdx);
    int roll = currPlayer.getRoll();;

    curr = currPlayer.getNextposition();
    System.out.printf("%s\n",currPlayer.getName());
    System.out.printf("Old: %d\n",currPlayer.getCurrposition());
    System.out.printf("Dice: %d\n",currPlayer.getRoll());
    System.out.printf("New: %d\n",currPlayer.getNextposition());

            if(curr==100) {
                menu=-1;
                break;
            }while (round<=25)

Ответы [ 3 ]

0 голосов
/ 21 апреля 2020

Ваша переменная round не отображается в l oop.

do {
    Player currPlayer = players.get(playerIdx);
    int roll = currPlayer.getRoll();

    curr = currPlayer.getNextposition();
    System.out.printf("%s\n",currPlayer.getName());
    System.out.printf("Old: %d\n",currPlayer.getCurrposition());
    System.out.printf("Dice: %d\n",currPlayer.getRoll());
    System.out.printf("New: %d\n",currPlayer.getNextposition());
    if(curr==100) {
        menu=-1;
        break;
    }   

    round++; // Added this too or the loop runs forever

} while (round <= 25);
0 голосов
/ 21 апреля 2020
do{
Player currPlayer = players.get(playerIdx);
int roll = currPlayer.getRoll();;

curr = currPlayer.getNextposition();
System.out.printf("%s\n",currPlayer.getName());
System.out.printf("Old: %d\n",currPlayer.getCurrposition());
System.out.printf("Dice: %d\n",currPlayer.getRoll());
System.out.printf("New: %d\n",currPlayer.getNextposition());
if(curr==100) {
    menu=-1;
    break;
}

} while (раунд <25) </p>

0 голосов
/ 21 апреля 2020

просто вставьте while(...) в конце

do {
    //Player takes turn
    Player currPlayer = players.get(playerIdx);
    int roll = currPlayer.getRoll();;
    //Update the board
    curr = currPlayer.getNextposition();
    System.out.printf("%s\n",currPlayer.getName());
    System.out.printf("Old: %d\n",currPlayer.getCurrposition());
    System.out.printf("Dice: %d\n",currPlayer.getRoll());
    System.out.printf("New: %d\n",currPlayer.getNextposition());
    if(curr==100) {
        menu=-1;
        break;
    } 
} while (round <= 25);
...