摇色子代码java java摇骰子( 三 )


java掷骰子(急)public class Test {
public static void main(String[] args){
DieGame dieGame = new DieGame();
if (dieGame.play()) {
System.out.println("你赢了!");
} else {
System.out.println("你输了!");
}
}
}
class Die {
private int faceValue;
public int getFaceValue() {
return faceValue;
}
public void setFaceValue(int faceValue) {
this.faceValue = https://www.04ip.com/post/faceValue;
}
public void roll() {
this.faceValue = https://www.04ip.com/post/(int) (Math.random() * 6 + 1);
}
}
class DieGame {
private Die die1 = new Die();
private Die die2 = new Die();
public boolean play() {
die1.roll();
System.out.println("第一次点数:" + die1.getFaceValue());
die2.roll();
System.out.println("第二次点数:" + die2.getFaceValue());
if (die1.getFaceValue() + die2.getFaceValue() == 7) {
return true;
} else {
return false;
}
}
}
【摇色子代码java java摇骰子】摇色子代码java的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java摇骰子、摇色子代码java的信息别忘了在本站进行查找喔 。

推荐阅读