Hello,
Thank you in advance for taking the time to help me!!
My assignment is to write a dice game in java using the Die.java class.The object of the game is to reach a total of 41 or more by rolling a pair of dice no more than 6 times. If you get 10, 20,30, or 40 as your total you automatically lose, and if you roll doubles you get an extra roll (however if you roll a 5 & 5 you loose).
I am having problems adding my turn totals !!! please help me.
for instance i get
Roll #1 5 2 Your total is : 7
Roll #2 3 1 Your total is : 7 when it should be 11
Roll #3 2 3 Your total is : 7 when it should be 16 and it keeps doing that for all the rolls
how do i get the turn total to add up after every roll?
I am just a beginner in programming so please be patient with me, and i apologize if didnt make myself too clear.
Thank you again!
public class FortyOne{
public static void main(String [] args){
Die die1, die2;
//Create a pair of dice
die1 = new Die();
die2 = new Die(6);
//Rolls dice
die1.roll();
die2.roll();
int rollCount;
rollCount = 0;
rollCount++;
//Initiate game
System.out.println("Let's Play 41!!!");
System.out.print("Roll #"+ rollCount+" ");
rollCount++;
// After the roll, prints out the value of die1 & 2.
System.out.print(die1.getUpValue() + " ");
System.out.print(die2.getUpValue() + " ");
//if you get doubles
if (die1.getUpValue() == die2.getUpValue())
System.out.print("YOU GOT DOUBLES!!! ");
//Gives turn total
int turnTotal = die1.getUpValue()+die2.getUpValue();
//prints out sum of die1 and die2
System.out.print("Your total is: " + turnTotal+ " ");
//Adds turnTotal to the next ?????
int playerTotal =0;
playerTotal+=turnTotal;
//gives the wining number
int winner= 41;
//Limits the amount of rolls to 6.
if(rollCount >=7)
System.out.println("YOU LOSE!!");
//Tells player they lose if their roll amount or total equals 10,20,30,or 40
if(turnTotal == 10 || turnTotal == 20 || turnTotal == 30 || turnTotal == 40){
System.out.println("\n" +" AW!! You lose! Sorry!");}
else if(playerTotal == 10 || playerTotal == 20 || playerTotal == 30 || playerTotal == 40){
System.out.println("\n" +" AW!! You lose! Sorry!");}
else
do {
System.out.print("\n" + "Roll #"+ rollCount+" ");
rollCount++;
die1.roll();
die2.roll();
die1.getUpValue();
die2.getUpValue();
System.out.print(die1.getUpValue() + " ");
System.out.print(die2.getUpValue() + " ");
System.out.print("Your total is: " + (turnTotal)+ " ");
} while (rollCount<=6);
rollCount++;
}
}
public class Die
{
private int numFaces;
private int upValue;
public Die()
{
numFaces = 6;
upValue = 1;
}
public Die(int faces)
{
numFaces = faces;
upValue = 1;
}
public void roll()
{
upValue = ((int)(Math.random() * numFaces)) + 1;
}
public int getUpValue()
{
return upValue;
}
}