trouble with while loop, not sure what to put in it in my project
I'm making a class to a simple command line craps game. I must use a while loop to implement craps rules. The rules that i was given are:
if your first roll is a 4, 5, 6, 8, 9, or 10, you roll again until either you get a 7 (you lose) or you get the number from your first roll. (i thought 7 or 11 wins, like in the next example)
yeah, thats right, not very good directions. The first directions i had for a different way of doing it using if and else statements were:
The player rolls the two dice.
If the sum of the resulting die values is 7 or 11, the player wins.
If the sum is 2, 3, or 12, the player loses.
If something else is rolled, the player has to roll again to determine the outcome.
If the sum of the second roll is the same as what the player rolled the first time, the player wins. Otherwise the player loses.
(You might get a pair of dice and play a few rounds to try it.)
here's my code that i have so far for my craps class, in the middle section, i have previous code that i used for if else statements, that is what im trying to replace:package games;
[code]
publicclass Craps{
private Dice dice1;
private Dice dice2;
privateint gamesPlayed;
privateint gamesWon;
privateboolean lastGameWon;
privateboolean gameOver;
privateint firstRoll;
privateint secondRoll;
public Craps(){
dice1 =new Dice(6);
dice2 =new Dice(6);
gamesPlayed = 0;
gamesWon = 0;
lastGameWon =false;
firstRoll = 1;
secondRoll = 2;
}
//returns firstroll
publicint getFirstRoll(){
return firstRoll;
}
//returns secondroll
publicint getSecondRoll(){
return secondRoll;
}
publicint getGamesPlayed(){
return gamesPlayed;
}
publicint getGamesWon(){
return gamesWon;
}
publicboolean lastGameWon(){
return lastGameWon;
}
publicint nextSum()
{
dice1.roll();
dice2.roll();
return dice1.getSideUp() + dice2.getSideUp();
}
publicvoid play()
{
firstRoll = nextSum();
if (firstRoll == 7 || firstRoll == 11)
{
gameOver =true;
gamesWon++;
}
if (firstRoll == 2 || firstRoll == 3 || firstRoll == 12)
{
gameOver =true;
}
else{
gameOver =false;
}
while (gameOver ==false)
{
secondRoll++;
}
}
public String toString()
{
return"games - " + gamesPlayed +", won - " + gamesWon +", last game won - " + lastGameWon +" First Roll - " + firstRoll +
", Second Roll - " + secondRoll;
}
}
i'm really confused on how to get the while loop will keep starting the game over if it is false, am i using the right approach? Also i have to use a while loop, its for a school project.
thanks.

