When a player rolls one 1 , or rolls 2 1s it needs to go to the next player, but at the moment it only goes to next player some of the time, while the rest of the time, it just continues with the same player. The problem is that when die1 || die2 == 1, the code should go to the next player, so the next while loop. and if there both 1, so the sum is 2, should go to next player. at the moment it just continues in the same while loop, and not sure how to make it go to next player/while loop
int p1 = 29, p2 = 0, turnp1 = 0, turnp2 = 0, signal = 1;
final int winningscore = 100;
while (p1 < winningscore || p2 < winningscore) {
turnp1 = 0;
while (turnp1 <= 20 && signal == 1 && p1 < winningscore && p2 < winningscore) {
int newp1total = p1;
System.out.println("Player 1s Turn!");
int die1 = player1.rollOne();
int die2 = player1.rollTwo();
int sumofdice = player1.sumOfRoll();
System.out.println("Player 1: First Die: " + die1 + " Second Die:" + die2 + " Sum of Roll: " + sumofdice);
if (sumofdice == 2) {
p1 = 0;
turnp1 = 0;
signal = -1;
System.out.println("Player rolled a two 1s. All players points are forfeited. Next Players turn.");
System.out.println("Points this turn:" + turnp1);
System.out.println("Points this game: " + p1);
System.out.println();
} else if (die1 == 1 || die2 == 1) {
turnp1 = 0;
signal = -1;
p1 = newp1total;
System.out.println("Player rolled a 1. All points on this round are forfeited. Next Players turn.");
System.out.println("Points this turn:" + turnp1);
System.out.println("Points this game: " + p1);
System.out.println();
} else {
turnp1 += sumofdice;
p1 += sumofdice;
System.out.println("Points this turn:" + turnp1);
System.out.println("Points this game: " + p1);
System.out.println();
signal = 1;
}
}
signal = 1;
String yesno = "y";
while (yesno.toLowerCase().equals("y") && signal == 1 && p1 < winningscore && p2 < winningscore) {
System.out.println("Player 2s Turn!");
int newp2total = p2;
int die1 = player2.rollOne();
int die2 = player2.rollTwo();
int sumofdice = player2.sumOfRoll();
System.out.println("Player 2: First Die: " + die1 + " Second Die:" + die2 + " Sum of Roll: " + sumofdice);
if (sumofdice == 2) {
p2 = 0;
turnp2 = 0;
signal = -1;
System.out.println("Player rolled a two 1s. All players points are forfeited. Next Players turn.");
System.out.println("Points this turn:" + turnp2);
System.out.println("Points this game: " + p2);
System.out.println();
} else if (die1 == 1 || die2 == 1) {
turnp2 = 0;
signal = -1;
p2 = newp2total;
System.out.println("Player rolled a 1. All points on this round are forfeited. Next Players turn.");
System.out.println("Points this turn:" + turnp2);
System.out.println("Points this game: " + p2);
System.out.println();
} else {
turnp2 += sumofdice;
p2 += sumofdice;
System.out.println("Points this turn:" + turnp2);
System.out.println("Points this game: " + p2);
System.out.println();
System.out.println("Try your luck? Y/N");
yesno = scan.next();
System.out.println();
signal = 1;
}
}
}
}
}
Aucun commentaire:
Enregistrer un commentaire