0
我需要帮助我的胡扯模拟游戏程序。谷歌可以很容易地找到掷骰子游戏的规则。我是使用Java的初学者,并希望你能和我一起袒露。对此,我真的非常感激!胡扯模拟游戏java
这是我到目前为止有:
public class Craps {
//static class variables
static int Random, r1, r2, n;
//declare variables to be shared between methods here
public static Random r;
public static Scanner in;
static {
r = new Random();
in = new Scanner(System.in);
}
//this method returns a value between 2 and 12
//to stimulate the roll of the two dice
public static int roll() {
for (int i = 1; i<= 2; i++) {
int r= (int)(Math.random()*12);
System.out.println(Random);
}
return 0;
}
//this method implements the rules of the game for one round
//it calls the roll() method to stimulate throwing the dice
public static boolean round() {
boolean print = false;
//if roll 7 or 11 = win
int roll1 = roll();
if (print==true) System.out.print(roll1);
if (r1==7||r1==11) {
System.out.print("Win");
return true;
}
//if roll 2, 3, 12 = lose
else if (r1==2||r1==3||r1==12) {
System.out.print("Lost");
return false;
}
//if point equals same number as rolled the first time, win
else {
int r2=roll();
int point = roll1;
}
return false;
}
public static void main(String []args) {
//call the "round()" method n times in a loop
//to play n rounds
int n = 10;
for (int i = 1; i<=n; i++) {
boolean result = round();
}
boolean print;
//collect wins/losses at the end of rounds, output wins/n as percentage
for (int wins=0; wins<n; wins++) {
System.out.println("Winning percentage: " + (100 * wins/n) + "%");
}
}
}
因此总结我的问题是:
- 难道我代表2和12之间的随机数生成正确刺激掷骰子在roll()方法中?
- 如何在round()方法中编写一个while循环来重复我的if-else循环决策以允许额外的卷?
- 我该如何创建一个变量“点”来继续滚动播放?
- 如何让用户输入轮次数“n”?
- 如何从命令行获取少量的用户输入作为在我的主要方法中创建扫描器的替代方法?
你到底在找什么?通过例子或更详细的解释来解释它。 –
请不要在您的代码中提出问题作为评论。 – tnw
欢迎来到Stack Overflow,noobeginner。此网站与您所期望的有所不同 - 它不是论坛,教程,也不是代码评论网站。这是一个非常特殊的问题和答案。花两分钟时间查看“两分钟之旅”,了解我们在这里所做的工作:http://stackoverflow.com/tour – RJHunter