【发布时间】:2016-12-15 22:46:13
【问题描述】:
我是 Java 新手,这是我必须做的:
如果玩家在 1 轮中 5 次在 2 个骰子上获得双六,则选择 10 到 30 之间的随机数。例如,如果该数字是 20,则其他两个骰子应掷 20 次,然后将这两个数字相乘并得到累积乘积。
这只是大计划的一小部分,这是我迄今为止所做的:
if (ninedice == 6 && sixdice == 6) {
rolledDoubleSix++;
if (rolledDoubleSix == 5) {
dicerolls = (int) Math.ceil(Math.random() * (30 - 10 + 1) + 10);
int ninediceproduct = dicerolls;
int sixdiceproduct = dicerolls;
if (ninediceproduct > 0) {
ninediceproduct=(int)Math.ceil(Math.random() * 9);
}
if (sixdiceproduct > 0) {
sixdiceproduct = dicerolls * (int) Math.ceil(Math.random() * 6);
}
int cumulativetotal = 0;
int cumulative = sixdiceproduct * ninediceproduct;
cumulativetotal = cumulativetotal + cumulative;
accountpoints = accountpoints + cumulativetotal;
accountptsoutput.setText("" + accountpoints);
我的问题是我不知道如何让两个骰子滚动特定的次数。如果 10 到 30 之间的随机数是 18,如何让这些骰子掷出 18 次?
【问题讨论】:
-
你了解过“for循环”吗?
-
不是很多。但这有什么帮助呢?
-
嗯,“for 循环”可以让您一遍又一遍地重复某些内容。看来你可能想要一个在这里。所以我建议阅读 Oracle 提供的在线 Java 教程。