class DiceGame()
{
private Die die1,die2;
public DiceGame()
{
die1 = new Die();
die2 = new Die();
}
public void play()
{
die1.roll();
die2.roll();
if(die1.getFaceValue() + die2.getFaceValue() == 7)
sout("you win");
}
}
class Die{
private int faceValue;
public roll()
{
Random rand = new Random();
faceValue = rand.nextInt(6) + 1;
}
public int getFaceValue()
{
return faceValue;
}
}
标签:对象,Die,die1,public,die2,new,getFaceValue,面对
From: https://www.cnblogs.com/jihuiting2/p/17705867.html