if (die1==1 && die2==1)
{ userMoney++;
JOptionPane.showMessageDialog(null, "You hit snake eyes, you won $1, and your value now is $"+userMoney);
}
if(die1==2 && die2==2)
{
userMoney+=2;
JOptionPane.showMessageDialog(null, "You hit double two, you won $2, and your value now is $"+userMoney);
}
if(die1==3 && die2==3)
{ userMoney+=3;
JOptionPane.showMessageDialog(null, "You hit double three, you won $3, and your value now is $"+userMoney);
}
if(die1==4 && die2==4)
{ userMoney+=4;
JOptionPane.showMessageDialog(null, "You hit double four, you won $4, and your value now is $"+userMoney);
}
if(die1==5 && die2==5)
{ userMoney+=5;
JOptionPane.showMessageDialog(null, "You hit double five, you won $5, and your value now is $"+userMoney);
}
if(die1==6 && die2==6)
{ userMoney+=6;
JOptionPane.showMessageDialog(null, "You hit double six, you won $6, and your value now is $"+userMoney);
}
if (die2 < die1)
userMoney-=die2;
if (die2 > die1)
userMoney-=die1;
if (userMoney < 1)
{
JOptionPane.showMessageDialog(null, "You have lost all your money. Have a great day :)");
System.exit(0);
}
System.exit(0);
}
}
I don't think we need array for this, do we? and how the heck do you get die1 and die1 into the public static void main(String [] args)? And it doesn't even roll :/
[ArchAngel added CODE tags]
10-25-2003, 07:49 PM
ArchAngel
This won't even compile!
It looks to me a classic case of continuing coding even if it doesn't work! You code seems quite confused and not very Object-Oriented.
Let me suggest this you write this program again, defining:
Code:
class Dice {
/**
* Rolls a single dice.
* @return A number between 1 and 6.
*/
public int roll();
}
...and then in your game code create TWO Dice objects (this is the joy of OO - you can just create another!).
Also, you scoring code could be much more efficient. Check first to see if the two dice values are equal i.e. result1 == result2 and then just add one of these values to the user's money i.e. money += result1.