java骰子游戏问题-请快
创建一个骰子游戏,玩家对电脑。游戏的要点是轮流掷骰子,第一个达到100胜。如果任一玩家掷2,他们的总掷骰数自动下降2。如果他们扮演其他角色,则会将其添加到运行总数中。第一个>=100胜。生成一个介于0和2之间的随机数,以决定谁先掷骰子。如果为0,则玩家首先掷骰,如果为1,则计算机首先掷骰 我是一个新手程序员在高中,我有很多麻烦与此。我通过将骰子卷单独列出,找到了如何单独显示骰子卷的方法。如果有人能告诉我一个更简单的方法,那就太好了,因为我不知道如何用这个方法找到第一个100个java骰子游戏问题-请快,java,methods,Java,Methods,创建一个骰子游戏,玩家对电脑。游戏的要点是轮流掷骰子,第一个达到100胜。如果任一玩家掷2,他们的总掷骰数自动下降2。如果他们扮演其他角色,则会将其添加到运行总数中。第一个>=100胜。生成一个介于0和2之间的随机数,以决定谁先掷骰子。如果为0,则玩家首先掷骰,如果为1,则计算机首先掷骰 我是一个新手程序员在高中,我有很多麻烦与此。我通过将骰子卷单独列出,找到了如何单独显示骰子卷的方法。如果有人能告诉我一个更简单的方法,那就太好了,因为我不知道如何用这个方法找到第一个100个 public cl
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));
}
}
这里的问题是,你限制了掷骰子的时间。在您的代码中,每个玩家的掷骰时间最多为10倍,这意味着如果他们每次掷骰得分都很低,他们将永远不会达到100。
您要做的是使用
while
循环,该循环将运行相同的代码,直到达到某个条件。
这是骨架,我会让你弄清楚剩下的;)
请注意,此类问题在本网站上并不受欢迎。你需要做的是理解你的代码的哪一部分不能工作。发布作业只会让你投反对票(尤其是标题中的“请快”会让你的问题被删除)。尝试将标题更改为类似于两名玩家之间的模拟骰子游戏,并重写该问题。你所说的“请快速”是什么意思?请发布你已经编写的代码。我们似乎缺少一个
fastplease
标记。我如何上传它?像“代码”一样编写它
while( no player reached a score of 100 ) {
player 1 roll the dice
add the result to player 1 score
player 2 roll the dice
add the result to player 2 score
}