【发布时间】:2016-12-20 10:41:04
【问题描述】:
创建一个玩家对电脑的骰子游戏。游戏的重点是轮流掷骰子,第一个达到 100 胜。如果任一玩家掷出 2,则他们的总数会自动减少 2。如果他们扮演其他角色,则将其添加到运行总数中。一拳>= 100胜。生成一个介于 0 和 2 之间的随机数来决定谁先滚动。如果为 0,则玩家先掷骰子,如果为 1,则计算机先掷骰子。
我是一名高中新手程序员,在这方面遇到了很多麻烦。我想出了如何通过单独列出所有骰子来单独显示骰子。如果有人能告诉我一个更简单的方法,那就太好了,因为我不知道如何使用该方法找到第一个到 100 的方法。
public class problemTwo {
public static void main(String[] args) {
// TODO Auto-generated method stub
int d1=(int)(Math.random()*6+1);
int d2=(int)(Math.random()*6+1);
int dSum= d1 + d2;
System.out.println("Player Roll 1 total is ;" +dSum);
int d3=(int)(Math.random()*6+1);
int d4=(int)(Math.random()*6+1);
int dSum2= d3 + d4;
System.out.println("Player Roll 2 total is ;" +dSum2);
int d5=(int)(Math.random()*6+1);
int d6=(int)(Math.random()*6+1);
int dSum3= d5 + d6;
System.out.println("Player Roll 3 total is ;" +dSum3);
int d7=(int)(Math.random()*6+1);
int d8=(int)(Math.random()*6+1);
int dSum4= d7 + d8;
System.out.println("Player Roll 4 total is ;" +dSum4);
int d9=(int)(Math.random()*6+1);
int d10=(int)(Math.random()*6+1);
int dSum5= d9 + d10;
System.out.println("Player Roll 5 total is ;" +dSum5);
int d11=(int)(Math.random()*6+1);
int d12=(int)(Math.random()*6+1);
int dSum6= d11 + d12;
System.out.println("Player Roll 6 total is ;" +dSum6);
int d13=(int)(Math.random()*6+1);
int d14=(int)(Math.random()*6+1);
int dSum7= d13 + d14;
System.out.println("Player Roll 7 total is ;" +dSum7);
int d15=(int)(Math.random()*6+1);
int d16=(int)(Math.random()*6+1);
int dSum8= d15 + d15;
System.out.println("Player Roll 8 total is ;" +dSum8);
int d17=(int)(Math.random()*6+1);
int d18=(int)(Math.random()*6+1);
int dSum9= d17 + d17;
System.out.println("Player Roll 9 total is ;" +dSum9);
int d19=(int)(Math.random()*6+1);
int d20=(int)(Math.random()*6+1);
int dSum10= d19 + d20;
System.out.println("Player Roll 10 total is ;" +dSum10);
System.out.println("Roll "+ " total is" +(dSum + dSum2 + dSum3 + dSum4 + dSum5+ + dSum6+ + dSum7+ + dSum8+ + dSum9+ + dSum10));
}
}
【问题讨论】:
-
“请快点”是什么意思?
-
请贴出你已经写好的代码。
-
看来我们缺少
fastplease标签。 -
如何上传?
-
写成'代码'